AutoHotkey Community

It is currently May 26th, 2012, 6:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Tetris game
PostPosted: March 17th, 2005, 10:03 pm 
Offline

Joined: February 27th, 2005, 5:51 pm
Posts: 139
Location: Heidelberg, Germany
Hi,

I tried to write a little game: Tetris. (I had the idea nearly at the same time like Invalid User, so this is not a copy of his version).

The script and bitmaps can be downloaded here:
http://niwi.ni.funpic.de/tetris.html

But there a still bugs and it is not really fast. Maybe someone has ideas to improve the speed so the game will be playable :-)

NiWi.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2005, 11:02 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Amazing! :o

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2005, 11:34 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
The speed is fine, but you're right about the bugs. I'm amazed at how nice it is already, though! I can only imagine how long this must have taken. All in all, it's a great proof of concept.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Tetris game
PostPosted: March 18th, 2005, 2:36 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
niwi wrote:
The script and bitmaps can be downloaded here:
http://niwi.ni.funpic.de/tetris.html
It looks great.

Quote:
ideas to improve the speed so the game will be playable
Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Tetris game
PostPosted: March 18th, 2005, 8:11 am 
Offline

Joined: February 27th, 2005, 5:51 pm
Posts: 139
Location: Heidelberg, Germany
Hi,

Chris wrote:
Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase?

One part which is very slow is removing a whole line because this also causes to "move" the whole upper part of the line one line down. At the moment I check if a line could be removed and move down the other bricks. After this I check the next line. I will change this and check from bottom to top if a line cann be removed, count the number of removed lines and move the upper part x lines down. This should speed up a little bit. But checking and moving is still slow.

An other problem is checking if a key is pressed. I use the hotkeys which I disable if a subroutine is called and enable at the end of an subroutine. This is necessary because the subroutines need some time to be processed and in this case it should not be possible to have an other subroutine called. Also the timer will be dis- and enabled while the program runs a subroutine.

Chris, is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?

NiWi.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Tetris game
PostPosted: March 18th, 2005, 1:43 pm 
Offline

Joined: February 9th, 2005, 9:18 pm
Posts: 17
Location: United States
This is really nice!
The only thing I noticed: upon downloading the script and attempting to execute it, I received the following error:

Quote:
Error: Parameter #3 must be a number in this case.

Specifically: v_speed
Line #
292: Transform,v_speed,Floor,v_speed

The program will exit.


After placing a ; in front of lines 291-294, the program worked fine, just didn't display the score.

Great job!

_________________
RG


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Tetris game
PostPosted: March 18th, 2005, 2:02 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
niwi wrote:
is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?
You could try reducing MaxThreads to 1 or 2:

#MaxThreads 1

The above would prevent your timer(s) from running except when the script is completely idle.

You could also use Suspend to disable all or some hotkeys temporarily, and re-enable them later:

Suspend On
...
Suspend Off

Finally, if you watch the CPU utilization during the removal of a complete row at the bottom and the CPU isn't maxed, that probably means there is a delay script somewhere, perhaps SetWinDelay or SetControlDelay (depending on the commands you're using).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2005, 3:56 pm 
Offline

Joined: February 27th, 2005, 5:51 pm
Posts: 139
Location: Heidelberg, Germany
Hi,

@RG:
the line 292 is wrong, it should be
Code:
Transform,v_speed,Floor,%v_speed%


@Chris:
The CPU is at nearly 100% :-(
But the idea with #MaxThreads is good. I still use the suspend on and off method, but maybe there is a little chance that a user starts another thread if the process runs between the label and the suspend command. I'm not sure, but if anyone know this, it should be you :-)

Code:
Label:
Suspend, On
...

But the maxthreads shall deny this.

NiWi.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2005, 3:54 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
niwi wrote:
The CPU is at nearly 100% :-(
There could be a bottleneck somewhere. For example, referring to a dynamic variable such as Array%i% is a fairly slow process. In such cases, resolve Array%i% only once if it is needed multiple times:

temp := Array%i%
x := temp
y := temp

Also, expressions are usually a little slower than traditional single-step math:

var := x / 3 + 100
Might be slower than:
var = %x%
var /= 3
var += 100

The really important thing to discover, however, is where the script is spending most of its time: often there are just one or two lines that are the problem, and sometimes there is a way to optimize them or do their work in a different way.

Quote:
I still use the suspend on and off method, but maybe there is a little chance that a user starts another thread if the process runs between the label and the suspend command.
I think it should be okay without suspend if you're using "#MaxThreads 1". You might also want to look up #MaxThreadsBuffer, which determines whether hotkey presses get deferred until later if the user presses one during a forbidden time (too many threads).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2005, 5:38 pm 
Offline

Joined: February 27th, 2005, 5:51 pm
Posts: 139
Location: Heidelberg, Germany
Hi,

I just copied the text from an other topic:
Chris wrote:
It's definitely faster. I don't get any long pauses anymore and it is very playable (my game skills are improving).

As a minor issue, when the game beat me, the script gave a syntax error because the use of a negative array index is illegal (since dashes are illegal in variable names):

Quote:
Error: This variable or function name contains an illegal character. The current thread will exit.

Specifically: v_Field[1][-1]

---> 741: __field := v_Field[%__xpos%][%__ypos%]
Thanks for making this great version of Tetris!

By the way, I've not yet tried the other Tetris script, but perhaps yours or the other one should go into the script showcase since it's a great demonstration of how to use arrays and GUI controls in creative ways (not to mention being fun).

Ok, I'll check this.

NiWi.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2005, 9:39 pm 
Offline

Joined: December 15th, 2004, 10:24 pm
Posts: 303
Location: United States
niwi wrote:
is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?


Thread, Setting, P2 [, P3]

"By default, every newly launched thread is uninterruptible for a Duration of 15 milliseconds or a LineCount of 1000 script lines, whichever comes first... If a hotkey is pressed or a custom menu item is selected while the current thread is uninterruptible, that event will be buffered. In other words, it will launch when the current thread finishes or becomes interruptible, whichever comes first. The exception to this is when the current thread becomes interruptible before it finishes, and it is of higher priority than the buffered event; in this case the buffered event is unbuffered and discarded."

Threads > Thread Priority > "The default priority is 0."

Solution: Set the desired subroutine to a higher priority than zero, and make sure its runtime is at least 15 ms (perhaps use Sleep 15 in the subroutine)..... This is the way to go. The only problem is, on this system anyway (Win2000 5.00.2195 SP4), i've tried the Thread command, and nonzero thread-Priority comparisons don't seem to be enabled. A fix would seem to be in order.

note: 1) during a timer's interruption, all timer commands will be acknowledged and buffered, then executed on resuming, 2) Thread: "...a thread will become interruptible the moment it displays a MsgBox, InputBox, FileSelectFile, or FileSelectFolder dialog."

_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2005, 1:39 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Decarlo110 wrote:
I've tried the Thread command, and nonzero thread-Priority comparisons don't seem to be enabled. A fix would seem to be in order.
This is a fairly complex area so it would help if you could post a short script to reproduce this problem, or just describe the nature of such a script.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group