Quote from: Blizzard on June 10, 2009, 04:57:18 am
The "Script is hanging" error on start up happens because the game is trying to connect to a host that doesn't exist (aka bogus IP). There's nothing that can be done about it except completely rewriting Ruby's socket class because it simply takes a while until the timeout of the socket is exceeded. And I'm not gonna do that because it might turn out that I actually have to go as deep as messing with Windows' API to actually fix that irrelevant problem. When you set up the servers in the game properly, it's not supposed to ever happen anyways.
Isn't that problem easily solved by having a thread controlling the socket and a thread controlling the rest?
Of course you may hit the problem with the Ruby interpreter pausing during Win32API calls, but that's a RMXP specific problem rather than a Ruby problem.
Either way this game really looks good :3
I can try that. I know that I wasn't able to get it running the last time. :/ Maybe I'm smarter now. xD
I know it's a breeze in Ruby, but you may be hindered by RMXP. Either way let's hope you are able to do it now that you have gotten even smarter :D
Quote from: Zeriab on June 10, 2009, 05:48:31 am
Isn't that problem easily solved by having a thread controlling the socket and a thread controlling the rest?
Of course you may hit the problem with the Ruby interpreter pausing during Win32API calls, but that's a RMXP specific problem rather than a Ruby problem.
Either way this game really looks good :3
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
Ruby threading is EVIL I say, EVIL!!!!!!!!!!!!!!!!!!!!!!!!!!
AND IT ISN'T THREAD-SAFE!!!!!!!!!!!!!!!! GAAAAAAAAAAAAAAAAAAAAAAADDDDDDDDD!!!!!!!!!!!!!!!!!!
But what you'd do is
SOCKET_THREAD = Thread.start do
while Thread.current["playing"]
<update_socket_code, but DON'T TOUCH ANYTHING GLOBAL OR USING ANY SINGLETONS, IF POSSIBLE>
Thread.current["<thread_variable>"] = <value>
*repeat above line as many times as you need*
end
end
# Scene Menu, dadadada....
def main
# stuff
loop do
<update_events_and_such_from_the_variables_in SOCKET_THREAD["<variable_name>"]>
ende
end
Of course it isn't thread-safe. Ruby is slow enough as it is.
Ruby for versions before 1.9 have their own scheduler for the threads. It's only at 1.9 that support for native threads have arrived. I haven't really tried it so I don't how the threading is. I only know for 1.8.1 & 1.8.5. You can always require 'thread' for the thread support classes such as providing semaphores and queues for inter-thread communication.
*hugs*
Quote from: Zeriab on June 10, 2009, 10:38:34 am
Of course it isn't thread-safe. Ruby is slow enough as it is.
Ruby for versions before 1.9 have their own scheduler for the threads. It's only at 1.9 that support for native threads have arrived. I haven't really tried it so I don't how the threading is. I only know for 1.8.1 & 1.8.5. You can always require 'thread' for the thread support classes such as providing semaphores and queues for inter-thread communication.
*hugs*
The thread-safe part was mainly me complaining. It makes Ruby extraordinarily sucky for a game engine. But, oh well :P
And 1.9 brings a lot of new stuff, like YARV. Fun stuff, too!
What are you talking about?
It's that the intention in RMXP is to only use a single thread for Ruby.
Besides it would be insane to have a completely thread-safe game engine. It would be far to slow.
It's only sharing of resources and communication between threads that should be designed to be thread-safe.
It's much worse that Graphics.update pauses all threads rather than just the thread calling the method and likewise with Win32API calls.
I wanna try 1.9 because I fear I may start using 1.9 specific stuff in RMXP Script.
We are going off topic so I we either should stop or take it elsewhere >_>
Quote from: Zeriab on June 10, 2009, 11:04:01 am
What are you talking about?
It's that the intention in RMXP is to only use a single thread for Ruby.
Besides it would be insane to have a completely thread-safe game engine. It would be far to slow.
It's only sharing of resources and communication between threads that should be designed to be thread-safe.
It's much worse that Graphics.update pauses all threads rather than just the thread calling the method and likewise with Win32API calls.
I wanna try 1.9 because I fear I may start using 1.9 specific stuff in RMXP Script.
We are going off topic so I we either should stop or take it elsewhere >_>
<FINAL POST> If you could use Ruby in one thread and still have it use resources from other threads, it'd be a different story, but it can't. You can't use any resources outside of the Ruby thread from within Ruby, which kills its usage as a game engine. It's still possible to multithread the engine, but it's not as effective as it could be.
And lol, I don't think 1.9 has that much new except for a few standard libraries being introduced, and you're already used to not using any Ruby libraries in RMXP (screw you, lack of support for Ruby extensions!)
ACTUALLY global data access in threads can be used without problems if you know how. :P
$clients = {}
server = TCPServer.new(host, port)
Thread.start (server.accept) {|tcp_connection|
c = Client_Connection.new(tcp_connection)
$clients.each_key {|connection| connection.send(0, "Entering: " + c.id.to_s)
$clients[c.id] = c
}
:P
I meant from the C side, where you can do actual game stuff X_X
Requiring .so files solves that problem.
Yeah it has been disabled in RMXP -_-
Either way can you make it work Blizzy? Can you prevent time outs :3?
Quote from: WcW on June 10, 2009, 01:48:59 pm
I meant from the C side, where you can do actual game stuff X_X
You have libraries with fully implemented semaphore and mutex handling (even though implementing a simply mutex yourself takes like 20-30 lines of code in
bad good old C).
@Z: Sure. :P
EDIT: .so == Unix type .dll :P
Quote from: Blizzard on June 10, 2009, 02:13:25 pm
Quote from: WcW on June 10, 2009, 01:48:59 pm
I meant from the C side, where you can do actual game stuff X_X
You have libraries with fully implemented semaphore and mutex handling (even though implementing a simply mutex yourself takes like 20-30 lines of code in bad good old C).
@Z: Sure. :P
EDIT: .so == Unix type .dll :P
Yes, which has been disabled. Unfortunately, there's an entire standard library full of extensions which exist in .so form, not .dll.
True. :/ This is probably because the intended RGSS to run on Windows so they didn't see any reason to leave the support for .so files. They probably didn't know .so's run fine on Windows. Stupid Enterbrain. :(
I don't know if RGSS is even based on real Ruby -- take the infamous ASCII and/or bug, for example.
Also, teh hawtness. (http://macruby.org) If only it were cross-platform )=
It is. RGSS is based on Ruby 1.8.6 if I remember right. It's a modded version though. RGSS means Ruby Game Scripting System after all.
Quote from: RMXP Help FileRPGXP's script engine doesn't use a proprietary simplified language, but the powerful scripting language Ruby. Ruby's official Website is http://www.ruby-lang.org/.
Ruby is freeware developed chiefly by Yukihiro Matsumoto, and its capabilities are more than sufficient to script a large-scale game. However, since it was originally conceived to be specialized in text handling and the like, it's a challenge to develop a game using Ruby alone. That's why RPGXP uses RGSS (the Ruby Game Scripting System) to adapt Ruby for use in game development. See the RGSS Reference for details.
The language can be referred to as "Ruby" or "ruby", but not as "RUBY".
what is a thread? is it like starting another process and running it through the processor separately but at the same time?
Yes, something like this. While two separate processes have access to different parts of the memory and both have their own memory, threads are within one process. They are branches that are being executed. The CPU switches about 10000 times between threads in one second. That was a program seems to be running more than just one piece of code parallelly. Imagine a server that runs a thread for each connected client. Usually multi-threaded applications are hard to debug because you need to take care of global memory access because two threads accessing and writing at the same memory location will nullify the action of one of them. It's undeterministic which will succeed so usually various mechanisms are used to ensure that threads work properly (i.e. locking of resources so only one thread can currently access that memory location).
As I said, it's not really running at the same time, but it's being simulated quite well.
Quote from: Blizzard on June 11, 2009, 05:14:12 am
Yes, something like this. While two separate processes have access to different parts of the memory and both have their own memory, threads are within one process. They are branches that are being executed. The CPU switches about 10000 times between threads in one second. That was a program seems to be running more than just one piece of code parallelly. Imagine a server that runs a thread for each connected client. Usually multi-threaded applications are hard to debug because you need to take care of global memory access because two threads accessing and writing at the same memory location will nullify the action of one of them. It's undeterministic which will succeed so usually various mechanisms are used to ensure that threads work properly (i.e. locking of resources so only one thread can currently access that memory location).
As I said, it's not really running at the same time, but it's being simulated quite well.
Unless, of course, you're using a multi-core process/multiple processors -- those
due run simultaneously in real-time. However, since the most cores the average PC has is 1-2, and only one of them, threads can still be ran on one-core at times. Yay for 8-core Nehalem, though!
True. Multi-core processors and multi-processor PCs do run threads at the same time.
Quote from: Blizzard on June 11, 2009, 01:52:51 pm
True. Multi-core processors and multi-processor PCs do run threads at the same time.
And then there's hyper-threading. There are some old single-cores with that.
In RMXP only one core is used so they won't run at the same time.
Quote from: Zeriab on June 11, 2009, 04:32:15 pm
In RMXP only one core is used so they won't run at the same time.
Because of the aforementioned "RUBY HAS NO THREAD-SAFETYZ!" Two cores can equal up to half as much lag (depending upon implementation), so if Ruby allowed for you to embed it into truly multi-thread applications, it'd be pretty nice. See what I meant?
Properly the reason to restrict the Ruby interpreter to 1 thread and use their own scheduler. That way it they don't have to deal with threads in the core.
I know that in practice you use multiple interpreters to utilize more cores or cpus. (It may have changed with 1.9 >_>)