Page 2 of 2

Re: New api in a OOP language?

Posted: Tue Oct 13, 2020 11:57 am
by Bilka
yagaodirac wrote:
Tue Oct 13, 2020 11:20 am
Bilka wrote:
Tue Oct 13, 2020 9:22 am
You could use something like https://github.com/TypeScriptToLua/TypeScriptToLua to write code in non-Lua, there is at least one mod on the mod portal that was written this way.
Which mod?
https://github.com/TGNThump/AbandonedRuins

(Just to be clear, this is a possibility, not a recommendation.)

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 12:47 am
by eradicator
yagaodirac wrote:
Tue Oct 13, 2020 5:05 am
Days ago, someone asked that does ue4 support python. After searching, I found ue4 supports python through a plugin.
So, is it possible to enable factorio to support js or py or anything else through a mod?
https://moonscript.org/ has similar syntax to python and compiles to lua.
Or maybe there's other compilers that can compile native python to lua?

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 2:29 am
by yagaodirac
eradicator wrote:
Wed Oct 14, 2020 12:47 am
yagaodirac wrote:
Tue Oct 13, 2020 5:05 am
Days ago, someone asked that does ue4 support python. After searching, I found ue4 supports python through a plugin.
So, is it possible to enable factorio to support js or py or anything else through a mod?
https://moonscript.org/ has similar syntax to python and compiles to lua.
Or maybe there's other compilers that can compile native python to lua?
I checked the web of moonscript. The last update was 5 years ago. Besides, I don't think the grammar is good enough. At least I'm not gonna give it a try.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 2:30 am
by yagaodirac
Bilka wrote:
Tue Oct 13, 2020 11:57 am
yagaodirac wrote:
Tue Oct 13, 2020 11:20 am
Bilka wrote:
Tue Oct 13, 2020 9:22 am
You could use something like https://github.com/TypeScriptToLua/TypeScriptToLua to write code in non-Lua, there is at least one mod on the mod portal that was written this way.
Which mod?
https://github.com/TGNThump/AbandonedRuins

(Just to be clear, this is a possibility, not a recommendation.)
Thanks.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 2:51 am
by yagaodirac
Bilka wrote:
Tue Oct 13, 2020 11:57 am
https://github.com/TGNThump/AbandonedRuins
Hi, emm, I think we misunderstood each other. I saw the lualib_bundle.lua file in that mod, but that lib is something like a std::vector. It's not what I care about.
Let's say, I'm gonna code a boss. I need to control the boss to move, shoot some projectile. Even in the very simplest case, the boss doesn't care where the players are, I need to be able to move the boss every tick. In ue4 or unity, all I need to do is that, override the AActor::tick(float) or the prefeb::update(float) respectively. It would look like
class boss: public AActor
{public:
void tick(float delta_time)
{
if (pos.x<100) pos.x+=5;else pos.x-= 5;//emmm, ok, please don't mind.
if (tick%30 == 0)shoot();
}
void shoot(){some code here.}
}
That's all. That's finished. Besides, I need a projectile class
class projectile: public AActor
{public:
void tick(float delta_time)
{
pos.y+=30;
}
}

But for now, in factorio api, I can't do this. And this is the critical reason that now a days factorio mods, scenarios are generally lack of entity movement control.
Normally people code in ue4 or unity don't rely on stl or boost. But they do rely on the infrastructure provided by the engine.
Would you official developers like to provide some framework, or should I do it myself?

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 3:22 am
by blazespinnaker
What mods are using Lua threads for doing things?.
Any mod that wishes to take advantage of multiple cores for performance reasons, I imagine. Kind of important these days

factorio is not a browser app that is meant to be restricted to have only a tiny slice of the cpu.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 5:19 am
by posila
yagaodirac wrote:
Wed Oct 14, 2020 2:51 am
Hi, emm, I think we misunderstood each other. I saw the lualib_bundle.lua file in that mod, but that lib is something like a std::vector. It's not what I care about.
As I said before, you are confusing language (C++'s std::vector is part of C++, but ue4's AActor is not) with engine/API architecture. What you want has nothing to do with a programming language or programming paradigm (like OOP), and everything to do with how the game and its API is architected. And that is not going to change.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 7:06 am
by ssilk
blazespinnaker wrote:
Wed Oct 14, 2020 3:22 am
What mods are using Lua threads for doing things?.
Any mod that wishes to take advantage of multiple cores for performance reasons, I imagine. Kind of important these days
I doubt mods ever become multithreaded. Some suggestions/discussions already about that. There are simple reasons for that.

I think the simplest way to explain it is, that only one process at any time can be enabled to modify the world.

And it really doesn’t matter. Very much cpu power gets lost in the api itself. Converting things, check mistakes etc. the more CPU’s a mod will have, the more it can use the API and the more CPU is used on top.

But for pure calculations in a mod, more power to calculate complex things this would be really nice and a factor of up to 100 is a thing, that really can change mod abilities...

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 8:04 am
by Klonan
yagaodirac wrote:
Wed Oct 14, 2020 2:51 am
But for now, in factorio api, I can't do this. And this is the critical reason that now a days factorio mods, scenarios are generally lack of entity movement control.
Normally people code in ue4 or unity don't rely on stl or boost. But they do rely on the infrastructure provided by the engine.
Would you official developers like to provide some framework, or should I do it myself?
Its trivially easy to do this using an on_tick event to just loop through all your entities.

The reason why mods don't do it, is because controlling things each tick with script is bad for performance.
No matter how the Lua script is called, either by some internal function override, or by calling it on tick, it is still going to be slow.

Factorio isn't a typical game. You can make 1 of your boss units, and it will be fine.
But in Factorio, scale beats everything. People will expand the map and have 10,000 of your boss units,
Or place 200,000 of your custom solar panels, etc.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 8:08 am
by Qon
blazespinnaker wrote:
Wed Oct 14, 2020 3:22 am
What mods are using Lua threads for doing things?.
Any mod that wishes to take advantage of multiple cores for performance reasons, I imagine. Kind of important these days

factorio is not a browser app that is meant to be restricted to have only a tiny slice of the cpu.
Not a single mod has ever used Lua threads, and even more definitly has it ever been used to increase performance. And never will. JS is also faster singlethreaded than Lua multithreaded so good riddance if we lose Lua and Lua threads in favor of getting a real and fast language like JS.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 8:15 am
by Klonan
Qon wrote:
Wed Oct 14, 2020 8:08 am
JS is also faster singlethreaded than Lua multithreaded
Do you have a source for that?

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 9:04 am
by Qon
Klonan wrote:
Wed Oct 14, 2020 8:15 am
Qon wrote:
Wed Oct 14, 2020 8:08 am
JS is also faster singlethreaded than Lua multithreaded
Do you have a source for that?
Has already been posted in this thread:
ssilk wrote:
Tue Oct 13, 2020 3:55 am
- js is really fast, I found benchmark which says up to hundred times https://benchmarksgame-team.pages.debia ... t/lua.html
I even doubt that any other pure script language is that fast.
Unless you think multithreaded programming in Lua can actually give any mods significant speedup to overcome that.

Any part of code that must run sequentially will of course limit the possible speedup that is possible (Amdahl's law).

For any writing API calls you would have to do that without breaking determinism. This might further limit the usefulness of Lua threads?

I don't know if the Factorio engine serve API calls to concurrent threads in parallel or sequentially. Multithreading might improve performance some anyways even if it doesn't run in parallel but it would also limit the potential for any speedup for mods with Lua threads if those are served sequentially.

So I'm saying that the gap is big enough that JS will be faster in general for pretty much all mods on the portal even with a very conservative estimate of JS being just a few times faster than Lua. Unless your implementation and modification of Lua is multiple orders of magnitude faster the Lua implementation that was benchmarked.

But I was trying to get balzaspinner to actually respond with an actual answer instead of the non-answer that I was given.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 10:34 am
by yagaodirac
For all of you talking about the multiple thread thing. The problem is that, if you make something fast enough, you definitely benefit from a multi core cpu. But if you host a game with this thing, people would probably have a hard time linking into your game. So, any mods that are design to be able to handle multiplayer situation, should avoid the fastest way of implementation. You basically shouldn't push a 3.6 ghz 2-core cpu to 75% load or even higher.
In this case, keeping everything single threaded is a good idea.

Re: New api in a OOP language?

Posted: Wed Oct 14, 2020 10:39 am
by yagaodirac
Klonan wrote:
Wed Oct 14, 2020 8:04 am
yagaodirac wrote:
Wed Oct 14, 2020 2:51 am
But for now, in factorio api, I can't do this. And this is the critical reason that now a days factorio mods, scenarios are generally lack of entity movement control.
Normally people code in ue4 or unity don't rely on stl or boost. But they do rely on the infrastructure provided by the engine.
Would you official developers like to provide some framework, or should I do it myself?
Its trivially easy to do this using an on_tick event to just loop through all your entities.

The reason why mods don't do it, is because controlling things each tick with script is bad for performance.
No matter how the Lua script is called, either by some internal function override, or by calling it on tick, it is still going to be slow.

Factorio isn't a typical game. You can make 1 of your boss units, and it will be fine.
But in Factorio, scale beats everything. People will expand the map and have 10,000 of your boss units,
Or place 200,000 of your custom solar panels, etc.
I knew this method from the beginning. As I know, this is how the ue4 and unity update their entities. So, the conclusion is clear, I need to make this framework. Yeah, what you worried is very practical. I know I need to limit the amount. Actually very few game design is about a giant amount of entities. Ok, I'm not gonna dig any more in this topic. Thank you for your replies.

Re: New api in a OOP language?

Posted: Thu Oct 15, 2020 2:15 pm
by blazespinnaker
well, you might be right. I'm not familiar with the mods, tbh. and, the factorio folks would have to use thread enabled lua, which they might not be.

another reason to use python, perhaps, which is pretty good at mt.

I am however rather skeptical of the benchmarking. THere's luajit, laua, etc. Lua can get very fast.

Re: New api in a OOP language?

Posted: Thu Oct 15, 2020 8:41 pm
by Hornwitser
blazespinnaker wrote:
Thu Oct 15, 2020 2:15 pm
another reason to use python, perhaps, which is pretty good at mt.
Python is not good at multithreading. CPython, the defacto implementation of the Python interpreter, has a something called the Global Interpreter Lock (GIL). Whenever a thread is executing Python code it holds the GIL and prevents any other thread from executing any Python code.

Re: New api in a OOP language?

Posted: Sat Oct 17, 2020 6:50 am
by yagaodirac
Klonan wrote:
Wed Oct 14, 2020 8:15 am
Hi, sorry to disturb you again. I hear that you prevented lua in custom mod to call functions in any other code? Means that I can't write any cpp code and call it from control.lua or data.lua? Thanks.

Re: New api in a OOP language?

Posted: Sat Oct 17, 2020 7:02 am
by Qon
yagaodirac wrote:
Sat Oct 17, 2020 6:50 am
Klonan wrote:
Wed Oct 14, 2020 8:15 am
Hi, sorry to disturb you again. I hear that you prevented lua in custom mod to call functions in any other code? Means that I can't write any cpp code and call it from control.lua or data.lua? Thanks.
Dude are you a troll? This is the third time you ask this question. viewtopic.php?f=25&t=90446

Re: New api in a OOP language?

Posted: Sat Oct 17, 2020 7:56 am
by blazespinnaker
Hornwitser wrote:
Thu Oct 15, 2020 8:41 pm
blazespinnaker wrote:
Thu Oct 15, 2020 2:15 pm
another reason to use python, perhaps, which is pretty good at mt.
Python is not good at multithreading. CPython, the defacto implementation of the Python interpreter, has a something called the Global Interpreter Lock (GIL). Whenever a thread is executing Python code it holds the GIL and prevents any other thread from executing any Python code.
very right. multiprocessing ftw.