Dolphin Smalltalk speed with Bitmap Operations

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Dolphin Smalltalk speed with Bitmap Operations

Frantisek Fuka
Hi all

I downloaded the Trial version of Dolphin Smalltalk because I tried to
develop a strategy game with realtime elements in Squeak Smalltalk and
unfortunately found its graphics routines much too slow for my needs.
That means I had to abandon my original idea of making the game
platform-independent and concentrate on Windows version.

But before I pay my hard-earned $250 (which is certainly much more
"hard-earned" in my country than in the "civilized world") I need to
know an answer to a few questions:

1) I'd like to know how quickly can Dolphin handle the sprite routines.
It seems that the simple answer is "as quickly as the Windows API" but
my problem is that I have zero experience with Windows API and also with
communicating between Smalltalk and the API so I didn't make much sense
of Dolphin's Bitmap operations which have almost no documentation and
consist primarily of Windows system calls. So I'd be very very glad if
someone could put together a very simple demo class for me that would
make X small bitmaps (for example circles 32 pixels in diameter) with
transparencies (masks) move across the screen without flickering (i.e.
using 2 screen buffers and switching them) and I could see how the speed
changes with changing the X number. All of this should be happening
inside window, not fullscreen! I was assured by mr. Bower from Dolphin
that this should be trivial but it's certainly not easy for me, being
not familiar with Windows systems calls and Dolphin Class structure.

2) Am I right in thinking that if I download the Microsoft documentation
for system calls (for example) for MIDI input and output, I can then
MYSELF add MIDI support directly to Dolphin Smalltalk without need of
having C-Compilers, linkers, etc, etc...?

3) Some of the classes (for example sockets) in Dolphin don't contain
source code. If I purchase the Full Version, will I get the access to
this source code? If not, how can I understand the methods? Certainly,
all of them are not documented.


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations

Costas Menico
The online documentation is quite good for Windows API reference.
Dolphin supports almost all of it.

You may also wish to checkout using DirectX or OpenGL for doing any
games work.

Check out http://msdn.microsoft.com/library and look for Graphics and
Multimedia

Here is an example of the documentation for sockets from msdn.

http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winsock/apistart_9g1e.htm


Reply | Threaded
Open this post in threaded view
|

SV: Dolphin Smalltalk speed with Bitmap Operations

Mikael Svane
"Costas Menico" <[hidden email]> skrev i meddelandet
news:[hidden email]...
>
>
> The online documentation is quite good for Windows API reference.
> Dolphin supports almost all of it.
>
> You may also wish to checkout using DirectX or OpenGL for doing any
> games work.
>

Another solution would be to use an ActiveX control. I have successfully
used SpriteX from Catalystpics in Dolphin. My SpriteX package, along with
some tutorials on how to use it is available at http://svane.swiki.net .

>3) Some of the classes (for example sockets) in Dolphin don't contain
>source code. If I purchase the Full Version, will I get the access to
>this source code? If not, how can I understand the methods? Certainly,
>all of them are not documented.

I have the professional version of Dolphin and the source code is available
in it.



Regards,

Mikael Svane
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations

Andy Bower
In reply to this post by Frantisek Fuka
Frantisek,

> 1) I'd like to know how quickly can Dolphin handle the sprite routines.
> It seems that the simple answer is "as quickly as the Windows API" but
> my problem is that I have zero experience with Windows API and also with
> communicating between Smalltalk and the API so I didn't make much sense
> of Dolphin's Bitmap operations which have almost no documentation and
> consist primarily of Windows system calls. So I'd be very very glad if
> someone could put together a very simple demo class for me that would
> make X small bitmaps (for example circles 32 pixels in diameter) with
> transparencies (masks) move across the screen without flickering (i.e.
> using 2 screen buffers and switching them) and I could see how the speed
> changes with changing the X number. All of this should be happening
> inside window, not fullscreen! I was assured by mr. Bower from Dolphin
> that this should be trivial but it's certainly not easy for me, being
> not familiar with Windows systems calls and Dolphin Class structure.

Please try the Bouncing Balls package that I've just whipped up and added as
a separate message in this thread (I didn't use an attachment since the
newserver I'm using doesn't allow them).  You should save the entire message
as "Bouncing Balls.pac" and use the package browser to install it into your
Dolphin 4 image. Follow the instructions in the package comment to bring up
the bouncing balls window.

The example demonstrates the use of a class called DoubleBufferedView for
providing flicker free animation. The idea is to subclass this and override
the #render method to paint each frame of your scene. This class will
probably be part of the standard image in the next version of Dolphin.

I've chosen to use Icons as sprites since these already have the capability
to provide masking. I've selected the icons for Model, View and Presenter
classes (see BouncingBallView>>initialize) for no other reason than they are
32x32 pixel balls. You could design your own using any icon editor for
Windows.

> 2) Am I right in thinking that if I download the Microsoft documentation
> for system calls (for example) for MIDI input and output, I can then
> MYSELF add MIDI support directly to Dolphin Smalltalk without need of
> having C-Compilers, linkers, etc, etc...?

That is correct. You'll need to read the Dolphin docs for interfacing to
external libraries at:

http://www.object-arts.com/Lib/EducationCentre4/htm/externalinterfacing.htm

> 3) Some of the classes (for example sockets) in Dolphin don't contain
> source code. If I purchase the Full Version, will I get the access to
> this source code? If not, how can I understand the methods? Certainly,
> all of them are not documented.

In the full version all classes include the source code.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---
>


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations (Bouncing Balls.pac)

Andy Bower
| package |
package := Package name: 'Bouncing Balls'.
package paxVersion: 0;
basicComment: 'Dolphin Smalltalk Bouncing Balls Animation Sample.
Copyright (c) Object Arts Ltd, 2001.
Implements a simple window of animated bouncing balls. To show the window,
evaluate:
BouncingBallView new show
You can control the frame rate and number of balls displayed by editing the
BouncingBallView methods #frameRate and #numberOfBalls respectively. If you
change the latter then you will have to open a new window.
The sample demonstrates the use of double buffering to provide
non-flickering animation. In this case we have chosen to use Icons for our
sprites since these already have the ability to support masking of the
graphic to a non-rectangular shape. Please note that no attempt has been
made to make the bouncing motion accurate (i.e. the balls don''t bounce off
the walls correctly or off each other at all).'.
package basicPackageVersion: ''.
"Add the package scripts"
"Add the class names, loose method names, global names, resource names"
package classNames
add: #Ball;
add: #BouncingBallView;
add: #DoubleBufferedView;
yourself.
package methodNames
yourself.
package globalNames
yourself.
package resourceNames
yourself.
"Binary Global Names"
package binaryGlobalNames: (Set new
yourself).
"Resource Names"
package allResourceNames: (Set new
yourself).
"Add the prerequisite names"
package setPrerequisites: (IdentitySet new
add: 'Dolphin';
yourself).
package!
"Class Definitions"!
Object subclass: #Ball
instanceVariableNames: 'position velocity icon'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
View subclass: #DoubleBufferedView
instanceVariableNames: 'backSurface requiresRender'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
DoubleBufferedView subclass: #BouncingBallView
instanceVariableNames: 'balls stepProcess'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
"Loose Methods"!
"End of package definition"!


Ball comment: ''!
Ball guid: (GUID fromString: '{09652D38-E87C-4CB5-B5FD-2D093FAE268B}')!
!Ball categoriesForClass!Unclassified! !
!Ball methodsFor!
drawOn: aCanvas
self icon drawOn: aCanvas at: (self position - (self icon extent / 2))
truncated!
icon
"Answer the value of the receiver's ''icon'' instance variable."
^icon isNil ifTrue: [self class icon] ifFalse: [icon]!
icon: anObject
"Private - Set the value of the receiver's ''icon'' instance variable to the
argument, anObject."
icon := anObject!
position
"Answer the value of the receiver's ''position'' instance variable."
^position!
position: anObject
"Private - Set the value of the receiver's ''position'' instance variable to
the argument, anObject."
position := anObject!
velocity
"Answer the value of the receiver's ''velocity'' instance variable."
^velocity!
velocity: anObject
"Private - Set the value of the receiver's ''velocity'' instance variable to
the argument, anObject."
velocity := anObject! !
!Ball categoriesFor: #drawOn:!*-unclassified!public! !
!Ball categoriesFor: #icon!accessing!public! !
!Ball categoriesFor: #icon:!accessing!private! !
!Ball categoriesFor: #position!accessing!public! !
!Ball categoriesFor: #position:!accessing!private! !
!Ball categoriesFor: #velocity!accessing!public! !
!Ball categoriesFor: #velocity:!accessing!private! !


DoubleBufferedView comment: ''!
DoubleBufferedView guid: (GUID fromString:
'{F0757E5D-E398-4EDE-9E0F-8C6CCB3699FC}')!
!DoubleBufferedView categoriesForClass!Unclassified! !
!DoubleBufferedView methodsFor!
canvas
"Answer a <Canvas> onto the back surface"
^backSurface canvas
setBkColor: self backcolor;
yourself
!
flip
"Private - Flip the current back surface to the front and paint it"
backSurface drawOn: super canvas at: 0@0 extent: backSurface extent. !
initialize
"Private - Initialise the receiver."
super initialize.
backcolor := Color white.
requiresRender := false.
!
initializeSurfacesFor: aPointExtent
"Private - Initialize the front and back surfaces for a view size of
aPointExtent"
| canvas |
backSurface notNil ifTrue: [ backSurface free ].
canvas := super canvas.
backSurface := Bitmap compatible: canvas extent: aPointExtent.
self invalidate.
!
invalidate
"Flag the current rendition as being invalid. A repaint will cause a
render to occur"
requiresRender := true.
super invalidate!
onCreated: anEvent
"Private - Handler for view created "
super onCreated: anEvent.
self initializeSurfacesFor: self extent.
!
onEraseRequired: aColorEvent
"Private - Handler for erase background"
^true!
onPaintRequired: aPaintEvent
"Private - Handler for paint event"
requiresRender ifTrue: [ self render ].
self flip.
!
onPositionChanged: aPositionEvent
"Private - Handle a window position change event (move or resize)."
aPositionEvent isResize ifTrue: [
self initializeSurfacesFor: aPositionEvent extent.
self repaint ].
^super onPositionChanged: aPositionEvent!
refreshContents
"The model held by the receiver has been changed so repaint"
self repaint
!
render
"Private - Render the background image"
requiresRender := false
!
repaint
"Repaints the receiver"
self render flip
! !
!DoubleBufferedView categoriesFor: #canvas!accessing!public! !
!DoubleBufferedView categoriesFor: #flip!operations!private! !
!DoubleBufferedView categoriesFor: #initialize!initializing!private! !
!DoubleBufferedView categoriesFor:
#initializeSurfacesFor:!initializing!private! !
!DoubleBufferedView categoriesFor: #invalidate!operations!public! !
!DoubleBufferedView categoriesFor: #onCreated:!event handling!private! !
!DoubleBufferedView categoriesFor: #onEraseRequired:!event handling!private!
!
!DoubleBufferedView categoriesFor: #onPaintRequired:!event handling!private!
!
!DoubleBufferedView categoriesFor: #onPositionChanged:!event
handling!private! !
!DoubleBufferedView categoriesFor: #refreshContents!public!updating! !
!DoubleBufferedView categoriesFor: #render!operations!private! !
!DoubleBufferedView categoriesFor: #repaint!operations!public! !


BouncingBallView comment: ''!
BouncingBallView guid: (GUID fromString:
'{247666E7-6B23-4E88-86D1-76D228924535}')!
!BouncingBallView categoriesForClass!Unclassified! !
!BouncingBallView methodsFor!
balls
"Private - Answer the value of the receiver's ''balls'' instance variable."
^balls!
defaultExtent
^200 @ 200!
defaultWindowStyle
"Private - Answer the default basic window creation style"
^##(WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
WS_MAXIMIZEBOX)!
frameRate
^30!
initialize
| rnd icons |
rnd := Random new.
icons := Array with: Model icon with: Presenter icon with: View icon.
super initialize.
balls := OrderedCollection new.
self numberOfBalls timesRepeat: [
| ball |
ball := Ball new
position: 100@100;
velocity: (rnd next*20) @ (rnd next*20);
icon: (icons at: ((rnd next*3) truncated + 1));
yourself.
self balls add: ball. ].
stepProcess := [[Processor sleep: (1000 // self frameRate). self step]
repeat ] fork!
numberOfBalls
^20!
onDestroyed
self stepProcess terminate.
^super onDestroyed!
render
"Private - Render the background image"
| canvas |
canvas := self canvas.
canvas erase.
"canvas backcolor: Color yellow; erase."
self balls do: [:each | each drawOn: canvas ].
canvas free. "useful to avoid build up of finalizable garbage"
super render
!
step
self balls do: [:each | | p v |
v := each velocity.
p := each position + v.
"Hit testing"
p x < 0 ifTrue: [
p x: 0.
v x: v x negated ].
p y < 0 ifTrue: [
p y: 0.
v y: v y negated ].
p x > self width ifTrue: [
p x: self width.
v x: v x negated ].
p y > self height ifTrue: [
p y: self height.
v y: v y negated ].
each position: p.
each velocity: v.
self invalidate ].

!
stepProcess
"Private - Answer the value of the receiver's ''stepProcess'' instance
variable."
^stepProcess! !
!BouncingBallView categoriesFor: #balls!accessing!private! !
!BouncingBallView categoriesFor: #defaultExtent!constants!private! !
!BouncingBallView categoriesFor: #defaultWindowStyle!constants!private! !
!BouncingBallView categoriesFor: #frameRate!constants!public! !
!BouncingBallView categoriesFor: #initialize!initializing!public! !
!BouncingBallView categoriesFor: #numberOfBalls!constants!public! !
!BouncingBallView categoriesFor: #onDestroyed!event handling!public! !
!BouncingBallView categoriesFor: #render!operations!private! !
!BouncingBallView categoriesFor: #step!operations!public! !
!BouncingBallView categoriesFor: #stepProcess!accessing!private! !
"Binary Globals"!
"Resources"!


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations (Bouncing Balls.pac)

Andy Bower
Folks,

Sorry about the lack of appropriate whitespace in my previous post of the
Bouncing Balls PAC file. Hopefully, it should work anyway even if it is a
little difficult to read. If there are real problems I can post the file on
the Object Arts web site.

BTW, one thing I forgot to mention about the package is this. From my meagre
experiments it seems that the limitation of the sample is in the size of the
window rather than the number of balls being bounced. For example you can
increase the number of balls to 200 with little perceived slow down in the
frame speed in small windows. However, if you increase the size of the
window you'll find the speed will decrease quite dramatically.

This is probably caused by the rather simplistic nature of the
DoubleBufferedView class. Perhaps someone armed with Ian Bartholomew's
profiler and a little time may be able to improve on this somewhat (although
I suspect it may be limited by Windows underlying ability to shift large
bitmaps at high frame rates). Of course the correct way to do this is to use
DirectDraw to implement the bitmap flipping since this will then be able to
make use of the DirectX hardware available in most modern graphics cards.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations

Ian Bartholomew-5
In reply to this post by Frantisek Fuka
Frantisek,

>                                               So I'd be very very glad if
> someone could put together a very simple demo class for me that would
> make X small bitmaps (for example circles 32 pixels in diameter) with
> transparencies (masks) move across the screen without flickering (i.e.
> using 2 screen buffers and switching them) and I could see how the speed
> changes with changing the X number.

I've put together a little demo called "bubbles" that, not surprisingly,
displays a view with lots of little bubbles rising from the bottom of the
view. It also includes two sliders so that you can dynamically (a) increase
the number of bubbles added after each iteration and (b) change the delay
(in milliseconds) between successive iterations of the loop. If the loop
(updating the bubble positions and redrawing the screen) can't be completed
in the specified delay than the system speaker is bleeped.

It's not as neat as Andy's demo, I used the "add on a bit and see what
happens" design technique, and I'm not sure it's the best way to implement
it but it might give some ideas. It's quite enjoyable to just sit and watch
it as well <g>

You can download it from

http://www.iandb.org.uk/~iandb/bubbles.zip

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations

Ian Bartholomew-5
In reply to this post by Frantisek Fuka
Apologies to all if this appears twice. My normal news posting service is
experiencing some problems and the original post seems to have got lost ...

------------

Frantisek,

>                                               So I'd be very very glad if
> someone could put together a very simple demo class for me that would
> make X small bitmaps (for example circles 32 pixels in diameter) with
> transparencies (masks) move across the screen without flickering (i.e.
> using 2 screen buffers and switching them) and I could see how the speed
> changes with changing the X number.

I've put together a little demo called "bubbles" that, not surprisingly,
displays a view with lots of little bubbles rising from the bottom of the
view. It also includes two sliders so that you can dynamically (a) increase
the number of bubbles added after each iteration and (b) change the delay
(in milliseconds) between successive iterations of the loop. If the loop
(updating the bubble positions and redrawing the screen) can't be completed
in the specified delay than the system speaker is bleeped.

It's not as neat as Andy's demo, I used the "add on a bit and see what
happens" design technique, and I'm not sure it's the best way to implement
it but it might give some ideas. It's quite enjoyable to just sit and watch
it as well <g>

You can download it from

http://www.iandb.org.uk/~iandb/bubbles.zip

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Dolphin Smalltalk speed with Bitmap Operations (Bouncing Balls.pac)

Smalltalkiano
In reply to this post by Andy Bower
Dear Andy,

    Ball is member of Actors 3D package so...

best regards..

Seb



"Andy Bower" <[hidden email]> escribió en el mensaje
news:9o9utt$brh8c$[hidden email]...
> Folks,
>
> Sorry about the lack of appropriate whitespace in my previous post of the
> Bouncing Balls PAC file. Hopefully, it should work anyway even if it is a
> little difficult to read. If there are real problems I can post the file
on
> the Object Arts web site.
>
> BTW, one thing I forgot to mention about the package is this. From my
meagre
> experiments it seems that the limitation of the sample is in the size of
the
> window rather than the number of balls being bounced. For example you can
> increase the number of balls to 200 with little perceived slow down in the
> frame speed in small windows. However, if you increase the size of the
> window you'll find the speed will decrease quite dramatically.
>
> This is probably caused by the rather simplistic nature of the
> DoubleBufferedView class. Perhaps someone armed with Ian Bartholomew's
> profiler and a little time may be able to improve on this somewhat
(although
> I suspect it may be limited by Windows underlying ability to shift large
> bitmaps at high frame rates). Of course the correct way to do this is to
use
> DirectDraw to implement the bitmap flipping since this will then be able
to

> make use of the DirectX hardware available in most modern graphics cards.
>
> Best Regards,
>
> Andy Bower
> Dolphin Support
> http://www.object-arts.com
> ---
> Are you trying too hard?
> http://www.object-arts.com/Relax.htm
> ---
>
>