Jump to content


Photo

Gmthreads 2 [updated: 30 Dec 2009]


  • Please log in to reply
211 replies to this topic

#1 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 04 August 2008 - 11:39 AM

Posted Image

Last update (30 dec 2009):

Features:
- GM8 support
- Added thread_wait function, with which you can wait for a specified thread until it'll finish executing the code
- Now you can check whether an error occured in a given thread
- Library has been rewritten to MASM
- Source released (on LGPL)

Compatibility issues:
- Some functions has been renamed (thread_priority, thread_affinity_mask, thread_ideal_processor, thread_num_of_processors)
- thread_last_error and thread_is_suspended functions has been removed.
- Now when creating a thread you must close its handle with thread_close function. This allows you to retrieve an error code after the thread terminates (thread_get_error).


FAQ style

What is it ?

GMThreads is a DLL library, which can execute given GML code in... threads ;D Actually, this is an "experiment" and it needs to be tested.

What "threads" are you talking about ? ;o

Hmm... I do not want to describe this so I will quote:

A THREAD in computer science is short for a thread of execution. Threads are a way for a program to fork (or split) itself into two or more simultaneously (or pseudo-simultaneously) running tasks. Threads and processes differ from one operating system to another but, in general, a thread is contained inside a process and different threads in the same process share some resources while different processes do not.
Read more...

In what these threads can be useful ?

Well, in threads code is executed all the time, even when the game window is minimized, moved, displays a message [show_message], room changes etc. Besides, with threads you can load resources etc. at runtime and main game window will not freeze (FPS may decrease, but this also depends on the priority of the thread)

So... how to use this ?

Maybe i'll list functions first:
thread_init( filename ) - Initializes GMThreads. Optionally, You can specify path to GMThreads DLL (default: GMThreads.dll).
thread_create( GMLCode, Suspended? ) - Creates a thread with task to execute given GML code. If second argument is set to 1 (true) then created thread will be suspended. Returns thread handle, which can be used by functions listed below.
thread_suspend( ThreadHandle ) - Suspends thread. Returns 0 if error occured, otherwise 1.
thread_resume( ThreadHandle ) - Resumes thread. Returns 0 if error occured, otherwise 1.
thread_set_priority( ThreadHandle, Priority ) - Changes given thread's priority. Returns 0 if error occured, otherwise 1.
Argument "priority" can be set to:


0 - Idle
1 - Low
2 - Below normal
3 - Normal (default)
4 - Above normal
5 - High
6 - Realtime

thread_get_priority( ThreadHandle ) - Returns thread's priority or -1 if error occured.
thread_get_error() - Returns error code of the specified thread. Error code is set after the thread terminates. Error codes:

-1 = Invalid handle specified
0 = No error occured
1 = Game maker error (not existing variables/objects, array index out of bounds etc) or other unexpected error.

thread_terminate( ThreadHandle ) - Forces termination of given thread. Returns 0 if error occured, otherwise 1. Warning: Threads terminated with this function are unable to free used resources, causing memory leaks.
thread_is_running( ThreadHandle ) - Checks whether thread is running.
thread_set_affinity( ThreadHandle, Mask ) - Sets affinity mask to specified thread.
More info can be found here:
http://msdn.microsof...247(VS.85).aspx
thread_set_processor( ThreadHandle, ProcessorNum ) - Sets preferred processor for specified thread.
More info can be found here:
http://msdn.microsof...253(VS.85).aspx
thread_get_cpucount() - Returns number of processors.
thread_wait( Thread Handle, Timeout ) - Waits until the specified thread will finish executing the code or specified timeout interval elapses. Timeout argument specifies time in miliseconds to wait until the thread terminates. If you pass -1 to the parameter the function will return only when the thread terminates.

Creating a thread:
New thread can be created with thread_create function. Returned value (thread's handle) should be stored in variable to control it with other functions.
my_thread = thread_create( "repeat (1000) global.variable += 1;", 1 ); // create thread (suspended)
if ( my_thread ) {
  thread_set_priority( my_thread, 2 ); // Change priority to "below normal"
  thread_resume( my_thread ); // resume thread
} else
  show_message( "Could not create a thread." );

That code will create a new thread with lower priority or show an message if function fails. ;p Simple, huh ?

In given GML code you can define variables ( local_variable = 0... ), but they cannot be accessed from other objects ( even that one, which call that function ), except global variables. After code execution thread will be terminated.

"Infinite" code execution in threads
That's simple too. ;D You can use the while loop. For example:
my_thread = thread_create( "
  while ( true ) {
	if ( something ) {
	  do_something();
	}
	variable += 0.1;
  }
", 0 );
But you must keep in mind that, the code is executed asynchronously to room_speed, so execution will cause more CPU usage. Sometimes you will need to delay loop with sleep() function:
my_thread = thread_create( "
  while ( true ) {
	if ( something ) {
	  do_something();
	}
	variable += 0.1;
	sleep( 1000 ); // wait second
  }
", 0 );

Terminating thread:
You can terminate a thread with thread_terminate function, but use it only if You really need to terminate a thread, because terminated with this function are unable to free used resources/memory, causing memory leaks. To terminate an thread safely, You must use statements:
my_thread = thread_create( "
  while (!global.terminated) { // execute until thread is about to terminate
	do_something();
	do_something();
	do_something();
	if ( global.terminated ) exit; // terminate on this line when thread is about to terminate
	do_something();
	do_something();
  }
", 0 );
and all You must to do is set global.terminated variable to true ;o

Note:
Thread is running even when room changes, so You have to check for existance of objects or variables. When error occurs in GML code (syntax error, unknown variable or object etc.) - thread will be terminated without showing any error messages. You can also use an comments in code ;D


Known bugs:
- In threads, messages such as "show_message" cannot be closed.
- In threads, all opened windows (like get_open_filename) are not blocking main game window.

Download (V2.0):
http://gmclan.org/up...GMThreads2.html (~9KB)
There's a simple example, DLL and the source code in the archive.

DLL is working only with GM6.1, GM7.0 and GM8.0

Edited by Snake_PL, 30 December 2009 - 09:42 AM.

  • 8

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#2 Doogie_Forever

Doogie_Forever

    Dog Warrior

  • GMC Member
  • 824 posts
  • Version:GM:Studio

Posted 04 August 2008 - 11:49 AM

Holy crap this sounds awesome, me and my friend were literally talking today about how cool GM would be with threads, definitely gonna try this.

Edited by Doogie_Forever, 24 May 2010 - 02:25 PM.

  • 0

#3 gnysek

gnysek

    GMC Member

  • GMC Member
  • 613 posts
  • Version:GM:Studio

Posted 04 August 2008 - 11:55 AM

It's very helpful. Great work!
  • 0

Previously game developer at YoYoGames, Currently PHP developer in DB-Team
Programming and working with: GML/C#/PHP/JS/MySql/CSS/HTML

Follow 
@GameMakerUpdate to get info about latest versions of GM when they are released: https://twitter.com/GameMakerUpdate or visit website.

(it's managed by bot, not by human, remember)


#4 Doogie_Forever

Doogie_Forever

    Dog Warrior

  • GMC Member
  • 824 posts
  • Version:GM:Studio

Posted 04 August 2008 - 11:56 AM

I know I'm old fashioned and should upgrade but would there be any chance in this being coded for Game Maker 5.3a as well?

And if not making it open source so another may do so.

I tested this out, works really well. This is simply an ingenious idea.
  • 0

#5 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 04 August 2008 - 12:10 PM

I know I'm old fashioned and should upgrade but would there be any chance in this being coded for Game Maker 5.3a as well?

Hmm... well, i'll try ;p

I tested this out, works really well. This is simply an ingenious idea.

Thanks.
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#6 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 04 August 2008 - 12:40 PM

Wow!
Great Job !
Any explanations as to how you achieved this via a DLL ?
  • 0

#7 gnysek

gnysek

    GMC Member

  • GMC Member
  • 613 posts
  • Version:GM:Studio

Posted 04 August 2008 - 12:51 PM

Maybe better question is why Mark Overmasrs said, that he will never put threads in Game Maker, because it will take too much time to write it... as we can see now, it's not to hard and takes a little time to write threading for GM.

Edited by gnysek, 04 August 2008 - 12:52 PM.

  • 0

Previously game developer at YoYoGames, Currently PHP developer in DB-Team
Programming and working with: GML/C#/PHP/JS/MySql/CSS/HTML

Follow 
@GameMakerUpdate to get info about latest versions of GM when they are released: https://twitter.com/GameMakerUpdate or visit website.

(it's managed by bot, not by human, remember)


#8 Robii

Robii

    GMC Member

  • New Member
  • 14 posts

Posted 04 August 2008 - 01:27 PM

Great DLL, Snake! ^_^ Make another useful DLL for us :D
  • 0

#9 nsm333

nsm333

    GMC Member

  • New Member
  • 230 posts

Posted 04 August 2008 - 01:30 PM

This is really useful! I've been looking for something like this. It solves one of my many problems!
  • 0
Hello, GMC. I've missed you all.

#10 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 04 August 2008 - 05:32 PM

This is nice. Thou how can I make it run every step? Or will it be even slower? Now the tread is executed one time. No function works to make it work more.

edit: btw, I always thought that treads in GM could be like surfaces. Something like tread_set_target(tread). Then the code to execute (like drawing for surfaces) and then tread_reset_target(). If it was built-in gm, then GM could be much faster don't you think? Things like AI, Physics and so on could be on different treads, and wouldn't it make the game run faster?

edit2: Why exactly can't the executed code get variables from local instance or some other ways? Because if global works, then why wouldn't any other variable type? Also, what exactly executes the code? GM with something like execute_string or the dll?

Edited by HaRRiKiRi, 04 August 2008 - 05:38 PM.

  • 0

#11 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 04 August 2008 - 06:09 PM

Things like AI, Physics and so on could be on different treads, and wouldn't it make the game run faster?


Only on computers with multiple cores or processors. On single cores this will just serve to make the game slower.
  • 0

#12 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 04 August 2008 - 06:24 PM

This is nice. Thou how can I make it run every step? Or will it be even slower? Now the tread is executed one time. No function works to make it work more.

Use "while" loop
thread = thread_create( "
  while (1) {
	// code
  }
", 0 );
// or
thread = thread_create( "
  while (1) {
	// code
	sleep( 1000 / room_speed );
  }
", 0 );

Why exactly can't the executed code get variables from local instance or some other ways?

Because code is not executed in any instance.

Also, what exactly executes the code? GM with something like execute_string or the dll?

GM ;p
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#13 nsm333

nsm333

    GMC Member

  • New Member
  • 230 posts

Posted 04 August 2008 - 06:31 PM

I can't seem to get something to work. How do I make it so that I can have a show_message, and then code being executed in another thread? It doesn't seem to do anything.
  • 0
Hello, GMC. I've missed you all.

#14 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 04 August 2008 - 06:59 PM

Only on computers with multiple cores or processors. On single cores this will just serve to make the game slower.

Thats what I wanted to say.

Use "while" loop

Ou, right. Sorry.

Because code is not executed in any instance.

Aa, but with () statement works as far as I know. So this isn't an issue.

GM ;p

Then this means two things.
1. We can use any variable we want, just using with statement.
2. This is kind of slow if used in continuation (every step). Because of the execute_string.

Does this support multiple cpu cores? I have core2duo, so can I make the tread to be executed on the other core? Because GM in default executes only on one core, and you can't change that.

There is a weird bug, sometimes the tread is not executed (skipping frames), so if the tread is for some movement calculations then the movement will be sluggish. Thou I guess this can be only used properly for loading in the background and stuff like that. This will allow proper loading screens, so thanks for this anyway.
  • 0

#15 gnysek

gnysek

    GMC Member

  • GMC Member
  • 613 posts
  • Version:GM:Studio

Posted 05 August 2008 - 07:48 AM

Huh, maybe if you want support of two cores, just write own application to write a game? Its just a Game Maker, and this DLL just helps to execute code in threads, no to optimize GM to super-ultra-high-supreme-speed application.
  • 0

Previously game developer at YoYoGames, Currently PHP developer in DB-Team
Programming and working with: GML/C#/PHP/JS/MySql/CSS/HTML

Follow 
@GameMakerUpdate to get info about latest versions of GM when they are released: https://twitter.com/GameMakerUpdate or visit website.

(it's managed by bot, not by human, remember)


#16 Blijbol

Blijbol

    Happy business

  • GMC Member
  • 313 posts

Posted 05 August 2008 - 10:03 AM

How in the world does your DLL execute GML code? Did you write your own GML interpreter?
  • 0
Blijbol OnScore 2 Extend your games with online highscore lists! New version!

Joystick OEM Name DLL Controller name as in Control Panel.
Registry Reader DLL Full read access to the Windows Registry.
Game Appearance Extension Control the game window and taskbar button in detail!
INI Data Structure Extension Much better than GM's INI functions.

Games and software: Slimeball Deluxe (digital arcade volleyball) Blijbol Snake 2 (traditional snake including a Maze Editor) Flood (try to escape from the water) Blijbol Memory (find the pairs) Game Maker Quiz (test your GM knowledge) More at Games.Blijbol.nl and Software.blijbol.nl
My website: Blijbol.nl (English/Dutch) | User of Game Maker 7.0 Pro | Moderator of the Dutch Game Maker Community

#17 gnysek

gnysek

    GMC Member

  • GMC Member
  • 613 posts
  • Version:GM:Studio

Posted 05 August 2008 - 10:21 AM

I don't think so. Looks, that compiled EMPTY exe weights about 2 MB, example game provided with this dll weights 17 kB, and this DLL weights 50kB - so it's much smaller than compiled game, which have interpreter, and not much bigger that game with so little code !
It must be another way.

Edited by gnysek, 05 August 2008 - 10:21 AM.

  • 0

Previously game developer at YoYoGames, Currently PHP developer in DB-Team
Programming and working with: GML/C#/PHP/JS/MySql/CSS/HTML

Follow 
@GameMakerUpdate to get info about latest versions of GM when they are released: https://twitter.com/GameMakerUpdate or visit website.

(it's managed by bot, not by human, remember)


#18 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 05 August 2008 - 03:33 PM

Huh, maybe if you want support of two cores, just write own application to write a game? Its just a Game Maker, and this DLL just helps to execute code in threads, no to optimize GM to super-ultra-high-supreme-speed application.

If he could make GM execute code in treads, then why couldn't he make them execute on a different cpu/core? I know that GM can't be optimized to super speed, but it can make it run faster. Treads is one of these ways.

How in the world does your DLL execute GML code? Did you write your own GML interpreter?

I don't think so. Looks, that compiled EMPTY exe weights about 2 MB, example game provided with this dll weights 17 kB, and this DLL weights 50kB - so it's much smaller than compiled game, which have interpreter, and not much bigger that game with so little code !
It must be another way.

He already stated that GM executes this code.
  • 0

#19 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 05 August 2008 - 05:28 PM

Snake? What have you done? Snaaaaake!!
This is really good. :blink:

Only on computers with multiple cores or processors. On single cores this will just serve to make the game slower.


But it won't crash the computer, right?
  • 0
GM 8.1 / GM:HTML5 User

#20 Potnop

Potnop

    GMC Member

  • GMC Member
  • 3103 posts

Posted 05 August 2008 - 05:59 PM

Cool. No it won't crash the computer, well it shouldn't. Multiple threads run on single core processors all the time. I think they have been since windows 95. It's the same idea as multiple processes running at the same time kinda...

Anyway...

How fast is this at executing the GML. Does it parse it itself and have to have all the runner code within itself or does it somehow use GM's runner code? And how would this work with extensions and stuff...
  • 0
Vegeta! What does the scouter say about his powerlevel?!? It's ovER 9000!!!!!
I ownt read da script, script reads me.


Link To The Super Crew Topic / Link To Colonial Commando Topic
Platform Pathfinding Example Download it here!
Editable Early Version Level Editor(Nice @$$ stuff, check it out) Download it here!

#21 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 05 August 2008 - 07:29 PM

Also, what exactly executes the code? GM with something like execute_string or the dll?

GM ;p

There's your answer.
  • 0

#22 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 05 August 2008 - 08:08 PM

How fast is this at executing the GML. Does it parse it itself and have to have all the runner code within itself or does it somehow use GM's runner code?

1. As fast as execute_string (in theory).
2. Uses GM to parse the code (I guess using execute_string).
3. Runs just like any other code. Can be used with extensions, dll's and so on. Just use with() statement. For ex., I made this work with GMP with just putting this in create:
thread_init();
thre=thread_create("while (1){with (obj_controll){update_bodies();} sleep (1000/room_speed);}", 1);
alarm[0]=1;
And this in alarm0:
thread_resume(thre);

Thou it will be jumpy and what not (the boxes will jump around and like every second or so some frames will be skipped. That is why I suggested not to use this in step event (or other continues event).

edit: typo's

edit2: Thou could work pretty good for multilayer..

Edited by HaRRiKiRi, 05 August 2008 - 08:26 PM.

  • 0

#23 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 06 August 2008 - 09:22 AM

Snake, you have to tell us how you are able/if you are able to access GM's interpreter. Because that opens up a a lot of possibilities for dlls and possibly help get arround a few issues...
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#24 MrJackSparrow2

MrJackSparrow2

    GMC Member

  • GMC Member
  • 632 posts
  • Version:GM:Studio

Posted 07 August 2008 - 05:34 AM

Snake, you have to tell us how you are able/if you are able to access GM's interpreter. Because that opens up a a lot of possibilities for dlls and possibly help get arround a few issues...

I don't think that he accesses the interpreter. But if so that would be amazing!
  • 0

#25 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 07 August 2008 - 05:42 AM

Snake, you have to tell us how you are able/if you are able to access GM's interpreter. Because that opens up a a lot of possibilities for dlls and possibly help get arround a few issues...

I don't think that he accesses the interpreter. But if so that would be amazing!


Then how do you think it has the same access to data and resources that GML does?
  • 0

#26 MrJackSparrow2

MrJackSparrow2

    GMC Member

  • GMC Member
  • 632 posts
  • Version:GM:Studio

Posted 07 August 2008 - 06:09 AM

Snake, you have to tell us how you are able/if you are able to access GM's interpreter. Because that opens up a a lot of possibilities for dlls and possibly help get arround a few issues...

I don't think that he accesses the interpreter. But if so that would be amazing!


Then how do you think it has the same access to data and resources that GML does?

I think we have a mis-understanding. The way I took his message was, he thought accessed the interpreter like gm games do on run time of a "compiled" exe.
Obviously using execute_string() is kind of "accessing" the interpreter, just not how I think icuurd12b42 is thinking the interpreter is "accessed".
  • 0

#27 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 07 August 2008 - 06:36 AM

Obviously using execute_string() is kind of "accessing" the interpreter, just not how I think icuurd12b42 is thinking the interpreter is "accessed".


Have you ever made a DLL? You can't just "use" functions from GM. The only (trivial) interaction between a DLL and the interpreter is the passing of values to and from the DLL. This does not trivially admit access to GM functions.
  • 0

#28 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 07 August 2008 - 08:50 AM

Obviously using execute_string() is kind of "accessing" the interpreter, just not how I think icuurd12b42 is thinking the interpreter is "accessed".


It is exactly what I'm asking. Yourself is also pretty much aware of why knowing this would be very useful to bypass GM's api call limit per step.

In GMFMODSimple, for example, getting wave data and spectrum data is very slow. If I can write to a global GM array right from c/c++...

GMBullet would also benefit and would be able to move more GM objects and even finally have a solution for jello/morphing models...

Another thing is playing videos right in the game. If I have access to the sprite resource... Even create and write to surfaces in the dll.

That is if the setup is fast and does not have the shortfalls of execute_string....

Edited by icuurd12b42, 07 August 2008 - 08:52 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#29 Clam

Clam

    GMC Member

  • New Member
  • 55 posts

Posted 07 August 2008 - 09:31 AM

I hate to say it, but this may not be permitted:

7. Discussions about altering/modifying Game Maker are not allowed. This includes tool bars, embedded windows, memory alteration, etc.

Although strictly speaking it doesn't directly modify memory, it definitely makes use of hardcoded pointers and calls the GM runner's internal functions without its "permission".

On a lighter note, I love it! :P. I will be interested to see how this topic progresses from here.
  • 0

#30 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 07 August 2008 - 09:55 AM

Clam i hope you realised this DOES not break the rules this does not break the rules because it does not do the following

altering/modifying Game Maker


altering/modifying Game Maker means actually adding stuff to game maker itself.

Edited by death-droid, 07 August 2008 - 09:57 AM.

  • 0

Posted Image


#31 Clam

Clam

    GMC Member

  • New Member
  • 55 posts

Posted 07 August 2008 - 10:08 AM

You'll notice I bolded memory alteration. I also explained that this doesn't strictly do that. What I'm getting at here is that there will probably soon be a new rule against this ;)

Perhaps next time you should actually read more carefully before you charge in the conquering hero and put me to shame for all to see. :P
  • 0

#32 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 07 August 2008 - 10:45 AM

You still dont get it a mod even posted here and did not say this is not allowed. Also this is not against the EULA or any rules it doesn't even modify memory it just adds support for something else if there was a rule against it then there will be only like on dll left here.
That rules means actual edits to Game Maker like adding toolbars to it.

Anyway pm me if you want to argue against what i said as i dont want to spam this topic.


This dll works flawlessly and adds a big speed advantage.
I recommend this to anyone that wants
  • 0

Posted Image


#33 OpticalLiam

OpticalLiam

    GMC Member

  • New Member
  • 782 posts

Posted 07 August 2008 - 08:40 PM

Well it appears to work very well, but care to tell us a little bit about how it does? Nice job.
  • 0

#34 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 07 August 2008 - 09:37 PM

In GMFMODSimple, for example, getting wave data and spectrum data is very slow. If I can write to a global GM array right from c/c++...


It might sound like a good idea, but you have to remember that this is executing GML. It's likely not accessing any structures directly. You'd end up with DLL code just as slow as GML in the first place which is precisely what you're trying to avoid.
  • 0

#35 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 07 August 2008 - 11:18 PM

In GMFMODSimple, for example, getting wave data and spectrum data is very slow. If I can write to a global GM array right from c/c++...


It might sound like a good idea, but you have to remember that this is executing GML. It's likely not accessing any structures directly. You'd end up with DLL code just as slow as GML in the first place which is precisely what you're trying to avoid.



Possibly but if he is able to access execute_string directly (assuption), we could access other things like ds_list_add.

Usually, the script we call in GML eventually map to a Native Function. If that is not the case (The scripts are implemented in GML and only available while in the interpreter) forget it.

Im hoping for this sort of implementation

gmexport double FillMyDataInA_ds_list()
{
	FARPROC ds_list_create= GetGMNativeHandlerFor("ds_list_create");
	FARPROC ds_list_add = GetGMNativeHandlerFor("ds_list_add");
	double listindex = (ds_list_create)();
	for(int i; i<1000;i++)
		(ds_list_add)(listindex,i);
	return listindex;
}
Anyway, before I actually see the code, I can only assume what the heck is going on in there.

Edited by icuurd12b42, 08 August 2008 - 03:37 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#36 Blijbol

Blijbol

    Happy business

  • GMC Member
  • 313 posts

Posted 08 August 2008 - 08:52 AM

If you can only access individual functions and variables from within a DLL, then Snake_PL still would have ended up writing a GML parser.
  • 0
Blijbol OnScore 2 Extend your games with online highscore lists! New version!

Joystick OEM Name DLL Controller name as in Control Panel.
Registry Reader DLL Full read access to the Windows Registry.
Game Appearance Extension Control the game window and taskbar button in detail!
INI Data Structure Extension Much better than GM's INI functions.

Games and software: Slimeball Deluxe (digital arcade volleyball) Blijbol Snake 2 (traditional snake including a Maze Editor) Flood (try to escape from the water) Blijbol Memory (find the pairs) Game Maker Quiz (test your GM knowledge) More at Games.Blijbol.nl and Software.blijbol.nl
My website: Blijbol.nl (English/Dutch) | User of Game Maker 7.0 Pro | Moderator of the Dutch Game Maker Community

#37 GearGOD

GearGOD

    Deus Verus

  • GMC Member
  • 2153 posts

Posted 08 August 2008 - 03:12 PM

A parser generates a goddamn token stream. How do you people manage to pick up these terms without picking up their meanings?

GML interpreter if anything.
  • 0
Engineers are not programmers. Stop thinking that you can save a few bucks by writing code yourself instead of hiring a programmer. Your code sucks.

#38 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 08 August 2008 - 08:32 PM

A parser generates a goddamn token stream. How do you people manage to pick up these terms without picking up their meanings?

GML interpreter if anything.


To be more specific, lexical analyzers generate token streams and a parser takes that token stream and determines if it makes sense (syntactic analysis). That is, a lexer gets the words from a sentence and the parser tells you if the sentence makes sense. The lexer can be separate from the parser, but it need not be. Still, the point of your post is to state that having a GML parser does not enable you to execute GML. It just enables you to say if a particular string is valid GML (and possibly to be able to convert it into an AST or some other data structure which could be fed to a runner which is entirely separate from the parser).
  • 0

#39 johnie102

johnie102

    GMC Member

  • New Member
  • 1608 posts

Posted 09 August 2008 - 03:17 PM

This. Is. Awesome.

But, how? How have you done this? Share your knowledge.

please...

EDIT: Why is it that you can't click on show_message() dialogs anyway?
Wait, you only have 9 posts... wow

Edited by johnie102, 09 August 2008 - 05:23 PM.

  • 0
Have I helped you? Thank me by playing my game


note that these graphics aren't in game... yet!

GENERATION 22: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

#40 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 09 August 2008 - 06:37 PM

If you try using Message boxes in threads, it would work totally differently then you would foretell.
I used to se ShowMessage() in delphi to debug (or check certain values). In the case of threads, messages start to appear one after an other, because multple threads doesn't halt on execution.

NB: Snake PL, I see you're starting to see some of the interesting aspects of pointers in GM. But, you'll probably get to the point I got to when all this scrambles up and won't work anymore (if you try using this differently). I know because I tried playing around with some aspects dscribed here. But I never planned or thought about using this for multithreading :lol:
  • 0

#41 johnie102

johnie102

    GMC Member

  • New Member
  • 1608 posts

Posted 09 August 2008 - 07:07 PM

Sadly, I have a bug to report:
if thread=-1 {
	switch (ds_queue_dequeue(loadList)) {
	case lvl_sand	: str="background_replace(back_default,working_directory+'\backgrounds\sand.jpg',0,1,1);";break;
	case lvl_dirt	: str="background_replace(back_default,working_directory+'\backgrounds\dirt.jpg',0,1,1);";break;
	case lvl_snow	: str="background_replace(back_default,working_directory+'\backgrounds\snow.jpg',0,1,1);";break;
	case lvl_spiral  : str="background_replace(back_default,working_directory+'\backgrounds\spiral.jpg',0,1,1);";break;
	case lvl_endless : str="background_replace(back_default,working_directory+'\backgrounds\endless.png',0,1,1);";break;
	case lvl_space   : str="background_replace(back_default,working_directory+'\backgrounds\space.jpg',0,1,1);";break;
	case lvl_invasion: str="background_replace(back_default,working_directory+'\backgrounds\invasion.png',1,1,1);";break;
	case lvl_lines   : str="background_replace(back_default,working_directory+'\backgrounds\metal.jpg',0,1,1);";break;
	default: str=""
	}
	if str!="" {
		thread=thread_create(str+"room_info_shower.thread=-1;",1);
				thread_priority(thread,2);
				thread_resume(thread);
	}
}

That would be all the relevant code. About 50% of the time it works flawless, but the other times it blackens my screen, comes back, deletes all my surfaces and nividia (the drivers) gives a small pop-up saying that it recovered from a crash. After that the background may have loaded (sometimes it loads half (so that you can see the previous room trough it)). I do not use the background in the room this is executing in.

Any help?

EDIT: Changing the code
if str!="" {
thread=thread_create(str+"room_info_shower.thread=-1;",1);
thread_priority(thread,2);
thread_resume(thread);
}

to
if str!=""
thread=thread_create(str+"room_info_shower.thread=-1;",1);

Seems to make this problem more bearable, but it still causes the screen to display some artifacts and screen flickering sometimes (and I got it to do the same as described above once).

Edited by johnie102, 09 August 2008 - 07:16 PM.

  • 0
Have I helped you? Thank me by playing my game


note that these graphics aren't in game... yet!

GENERATION 22: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

#42 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 09 August 2008 - 11:32 PM

Welcome to multi-threading... Here you will learn why games are rarelly multi-treaded.

your problem here, above, if that you are hitting points in time where you are modifying backgrounds at the same time the main thread is reading it. Causing crashes or artefacts...

At this point you need to synchronize the threads (yours and GM's) so that this does not happen. That operation alone can slow the game down more than if the game was single threaded.

example, for thread screwing arround sprites

while(true)
{
while(global.MainIsUsing <> 0) {do nothing}
global.ThreadIsLoading = 1;
load/change sprite from file for sprites 1,2,3,4,5,6,7,8,9
global.ThreadIsLoading = 0;
}

in gm:
begins step of a controller or the draw of the last drawn object
global.MainIsUsing = 0;

in end step or the draw in a very deep object (first drawn)
while(global.ThreadIsLoading <> 0) {do nothing}
global.MainIsUsing = 1; //will be using the sprites during the paint



IMPORTANT

note the if conditions
if (values <> 0)

and the setting
setting to 0 or 1

That is imprtant, at least in machine/c/assembly language

if a thread is writing to a value while another is reading it, the reader will/could read garbage... that is he could read something other than what is being written. So the if statement is only truly valid if the value is 0, 1 or garbage would mean the other thread is in the critical section or writing to the variable to set the state.

Edited by icuurd12b42, 09 August 2008 - 11:40 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#43 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 09 August 2008 - 11:41 PM

I just wonder how this DLL prevents race conditions with regular variable access. Variable access in GM is very likely not an atomic operation.
  • 0

#44 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 10 August 2008 - 12:03 AM

I just wonder how this DLL prevents race conditions with regular variable access. Variable access in GM is very likely not an atomic operation.


It is best to never have 2 thread write to the same address (variable), in any language to avoid such problem. Thread 1 out reads from thread2's out variable and writes to it's out variable... Thread 2 read data from thread1's out variable and writes to it's out variable. In any case, it best to lock the other thread before reading.

I hit some problems a long time ago where I would have problems even with locking when writing a large amount of data. This is resolved by inplementing sychonization (my previous post) or fifo buffers for communication...

Mutli-threaded shared data is a b*tch to handle sometimes. Using out fifo buffers was the fastest means I found, where I did not even need to lock the other thread. It was a long time ago. A time where threading was at it's infancy. So I used hardware methods applied in software (fifo out buffers)....

Edited by icuurd12b42, 10 August 2008 - 12:07 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#45 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 10 August 2008 - 08:48 AM

johnie102: You should load them in a loading screen. Make something like global.loading=true and in every draw event (or in ones that use the resources you load) put if (global.loading=true){..}. You may also (which is better) make a loading screen, which is a seperate room in which you can load the resources, in the same time showing an animated loading screen or something.
  • 0

#46 johnie102

johnie102

    GMC Member

  • New Member
  • 1608 posts

Posted 10 August 2008 - 10:11 AM

Let me explain my problem further:
Every background is 1000*700 which is pretty large. To keep memory consumption lower I only load the background that is needed. I don't want the player to wait while loading the background so I replace the background with the right one when the user clicks the map in the map selection screen, so that the background is already loaded when you go to the room of the map. I already understood that you couldn't write to the same variable multiple times so I made a ds_queue to store what background should be loaded next. This makes sure that only 1 extra thread is running and is accessing the background. I am not using that background in the room that I'm modifying it in, so I don't see how I am interfering with the background.

@icuurd, so that makes sure you aren't modifying sprites/background while the draw event is executing? But if I'm not using the background in that room that shouldn't matter, right?
  • 0
Have I helped you? Thank me by playing my game


note that these graphics aren't in game... yet!

GENERATION 22: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

#47 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 12 August 2008 - 02:31 PM

it definitely makes use of hardcoded pointers and calls the GM runner's internal functions

Yeah, that's exactly what it does ;D

There's a new version:
Fixed: Memory leaks

Download:
http://www.gmclan.or...MThreads13.html
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#48 johnie102

johnie102

    GMC Member

  • New Member
  • 1608 posts

Posted 12 August 2008 - 02:46 PM

I just want to say I fixed the error:
Turn OFF preloading.

It fixes everything. Thanks for this wonderful DLL.

EDIT: I think you should put that in the first post of this thread.

Edited by johnie102, 12 August 2008 - 05:10 PM.

  • 0
Have I helped you? Thank me by playing my game


note that these graphics aren't in game... yet!

GENERATION 22: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

#49 Doogie_Forever

Doogie_Forever

    Dog Warrior

  • GMC Member
  • 824 posts
  • Version:GM:Studio

Posted 19 August 2008 - 08:05 AM

Snake_PL, Im sure many people would benefit from this if you release the source, ever thought about it?
  • 0

#50 weirdo_studios

weirdo_studios

    GMC Member

  • New Member
  • 174 posts

Posted 19 August 2008 - 11:42 AM

nice this is an extremely useful dll, especially for mmo's when running on a quad-core machine ^^
also for loading large backgrounds(realtime) as you demonstrated this is no problem at all. this also seems easier to use than REAL for loading, except it might be slower.

thank you for sharing this great dll! :)
  • 0