View Single Post
Old 02-13-2012, 05:48 PM   #4
camlorn
Member
 
Join Date: Aug 2011
Posts: 144
camlorn is on a distinguished road
Re: High volume scripting question

Hi,
So I'm no expert on programming or anything, but I'm curious about stuff and did look at this issue. A few thoughts which may or may not be good ideas; take these with a grain of salt.

First, lua has something called coroutines, which basically lets you pause and play executing scripts; this would allow you to simulate multitasking. Have each script execute for a set time each iteration through the loop, pause, handle whatever, and start again.

As for script integrity, in general, that's a very tricky issue. I'd say don't let scripts touch anything manipulated by the engine, and the engine anything by the scripts, but that does limit a lot of possibilities. Iirc, coffeemud did something like that; if you wish your script or whatever to affect a player, say, int +2, you send out a message that says you're now affecting the player that way, and the player class handles applying your affect in the math.

But, my immediate idea would be this: a critical block. That's a name I gave it; there probably is an actual name out there for it. Basically, have a method, begincritical() and endcritical(), such that the script is garenteed to run uninterrupted from the beginning to the end. The major drawback to that is that now, to use this safely, builders have to know about threading and when to (not) use it. There's a variety of approaches out there, if you want to go that route, look up thread safety and mutex.

In line with the above, have objects marked as unmodifiable and make the game engine not touch them until they become modifiable again; this is basically clallbacks, and is really a suboptimal sollution.

Finally, I really don't think you should see that much slowdown. The easiest bit is to have the engine only execute so many scripts each time through the main loop; players aren't giong to notice errors from that. But that again introduces possible bugs.

Honestly, if you're creating the area with these on idle scripts, don't; implement it in the codebase. If you're just making the mobs say a random line, there's some functionality to add to olc. Also look at optimizing the actual functions that scripts call into. I know gcc has a profiler which looks halfway decent, as does visual studio ultimate which isn't free by any means.

Just some (useless?) thoughts.
camlorn is offline   Reply With Quote