|
|
|
|
|
|
|
|
|
|
What's News in the PlayBasic world ? - Find out here.
PlayBasic V1.64N2 Retail Upgrade Released
|
By: Kevin Picone Added: July 26th, 2012
|
Category: All,Upgrade
|
PlayBasic V1.64N2 _Retail Upgrade_ is Available (25th, July, 2012)
The V1.64N2 upgrade was originally planned as a quick upgrade to just address a few bugs with a small documentation pass. But that quickie soon turned into one of the more important additions in years, with the introduction to the Type + Array Cache optimizers to the compiler. Beyond that, the upgrade features a number of low level speed improvements to every day operations ranging from the loops (For/next , For Each + Repeat/While loops) , General Comparisons through to complete opcode rearrangement of the Image/Sprite command sets. The goal of which being to shave as many wasted cycles from all of the every day operations as possible. It's this attention to detail that see's V1.64N2 being able to execute our standard performance benchmarks up to 1/2 a second quicker than V1.64N. Pretty impressive, given that I personally had thought V1.64N wouldn't be beaten, but things change.
In terms of the compiler, the TYPE CACHING features the are the real show pony of this upgrade. What caching does, is it tracks Type and Array usage throughout a program. In older versions of PlayBasic, pretty much every time a typed variable / array or linked list was accessed, the compiler would drop the required (long hand) operations to resolve that operation. Even if the following operation was similar. This is where caching steps in, now the compiler can detect such situations and is able to short cut the reading /writing if type structures. Given that type usage is generally serialized in code blocks, this can double, even triplet the through put of some routines.
Now for the most surprising thing, Type Caching isn't enabled by default. Why ? - Well in classic version of PlayBasic, the user is allowed to read types that doesn't actually exist, without the program falling over. Unfortunately this behavior can play havoc with caching in some programs, so the type cache mode is turned off the default. You can enable it by using the OptExpressions 3 command, it's perfectly safe provided your program only ever read/writes into types that exist. The optexpressions command allows the programmer to toggle the user controllable optimization modes on or off through out a program.
Here's an example of some code that can be potentially unsafe with caching enabled, that you might find in many older PlayBasic programs.
Type Person
Status
X#,y#
EndType
DIm people(10) as Person
; create the person at index #1 in the array
People(1) = new Person
; set it's fields
People(1).Status = True
People(1).x = 100
People(1).y = 200
; Run through all of the people in the array
For lp =1 to 10
; Read this type and grab the STATUS field
; if the status field is set, run code inside
if People(lp).Status
; DRaw This Person as a circle
Circle People(lp).x,People(lp).y,50
endif
next
; Show the Screen and wait for a key press
Sync
waitkey
What makes this unsafe is that the inner IF statement is attempting to read the STATUS field from every person in the array. When it's reading person at index #1 in the array, the expression is true and person is drawn as circle on screen. But on the next iteration of the loop, the IF statement is attempting to read a field from that cell in the array that doesn't exist. In other languages you might expect this give you a runtime error, but PB would original just return a zero from those reads. V1.64N2 keeps this behavior in order to run older PlayBasic programs, but it works differently when caching is fully enabled.
In this version, the IF statement isn't trying to read a FIELD from the various types in the people array, rather it's reading the array cell contents directly. Empty cells in the Typed array will be ZERO, anything else and a type exists at this position. So we can happily pre-screen for the existent of a type in array like the following.
Type Person
Status
X#,y#
EndType
Dim people(10) as Person
; create the person at index #1 in the array
People(1) = new Person
; set it's fields
People(1).Status = True
People(1).x = 100
People(1).y = 200
; Run through all of the people in the array
For lp =1 to 10
; Read this type and see if there's anything
; at this position in the array. If it returns
; zero, there's no type there, anything else and
; this type exists.
if People(lp)
; DRaw This Person as a circle
Circle People(lp).x,People(lp).y,50
endif
next
; Show the Screen and wait for a key press
Sync
waitkey
This version is perfectly type caching friendly.
Documentation
This upgrade also features another fairly heavy pass over the documentation, which various tutorial additions and media & content additions. Tutorial wise there's a huge new tutorial all about sprites. Starting with Images and moving through to the sprite commands, which turned out to be the way bigger than I'd ever expected. From memory, it's the biggest tutorial ever.
Don't have a retail version of PlayBasic and want to find out more information about PlayBasic programming > please visit the Downloads page for the free learning edition.
Download
Download V1.64N2 Upgrade
Work In Progress
We recommend checking out the V1.64N2 WORK IN PROGRESS GALLERY for more insights into the latest additions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|