Tcl Source Code

Check-in [8e4b3d24c5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added 'natcl2tk' wrapper to run the same demo in true Tk, for speed comparisons.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ferrieux-nacl
Files: files | file ages | folders
SHA1: 8e4b3d24c552ff90d3870a3aedeef906c57ee4cf
User & Date: ferrieux 2011-04-16 16:01:18
Context
2011-04-18
21:22
Use closures rather than strings for after and [every] check-in: 06e1f26911 user: ferrieux tags: ferrieux-nacl
2011-04-16
16:01
Added 'natcl2tk' wrapper to run the same demo in true Tk, for speed comparisons. check-in: 8e4b3d24c5 user: ferrieux tags: ferrieux-nacl
2011-04-15
12:15
Cleanup of updateStatus() check-in: 1a6ada0a28 user: ferrieux tags: ferrieux-nacl
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to nacl/README.

153
154
155
156
157
158
159







160
161
162
163
164
JS version,  so at  40fps it consumes  a full  core of my  2GHz laptop
(against 33% for the JS one). 

One should  note that the pure  string API used precludes  any used of
the  internal reps of  coordinates, so  there are  many string/integer
conversions. To be continued.








Future work
-----------

 Coming soon: [domget], more [canvas] features, and optimizations ;-)








>
>
>
>
>
>
>





153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
JS version,  so at  40fps it consumes  a full  core of my  2GHz laptop
(against 33% for the JS one). 

One should  note that the pure  string API used precludes  any used of
the  internal reps of  coordinates, so  there are  many string/integer
conversions. To be continued.

Comparison with native Tcl/Tk
-----------------------------

With the  command 'tools/natcl2tk balls.natcl',  you can run  the same
code  in pure  Tcl/Tk,  in a  true wish  canvas.  You can  use it  for
performance and rendering comparisons.

Future work
-----------

 Coming soon: [domget], more [canvas] features, and optimizations ;-)

Changes to nacl/balls.html.

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
</head>

<body onload="pageDidLoad()">

<h1>NaTcl -- Native Client Tcl Module</h1>
<p>

  <canvas id="canvas" width="576" height="300"></canvas>

  <!-- Load the published .nexe.  This includes the 'nacl' attribute which
  shows how to load multi-architecture modules.  Each entry in the "nexes"
  object in the  .nmf manifest file is a key-value pair: the key is the runtime
  ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
  To load the debug versions of your .nexes, set the 'nacl' attribute to the
  _dbg.nmf version of the manifest file.







|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
</head>

<body onload="pageDidLoad()">

<h1>NaTcl -- Native Client Tcl Module</h1>
<p>

  <canvas id="canvas" width="578" height="200"></canvas>

  <!-- Load the published .nexe.  This includes the 'nacl' attribute which
  shows how to load multi-architecture modules.  Each entry in the "nexes"
  object in the  .nmf manifest file is a key-value pair: the key is the runtime
  ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
  To load the debug versions of your .nexes, set the 'nacl' attribute to the
  _dbg.nmf version of the manifest file.

Changes to nacl/balls.natcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
source canv.natcl
#set ::canv_verbose 1
domset statusField "Running..."

# will be retrieved by [domget]
set width 576
set height 300

# animation globals
set t 0
set frameInterval 25

# ball globals
set ballRadius 10





|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
source canv.natcl
#set ::canv_verbose 1
domset statusField "Running..."

# will be retrieved by [domget]
set width 578
set height 200

# animation globals
set t 0
set frameInterval 25

# ball globals
set ballRadius 10

Added nacl/tools/natcl2tk.





































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/sh
#\
exec wish $0 "$@"

if {!$argc} {
    puts stderr "Usage: [file tail $::argv0] <file.natcl> \[<file.natcl> ...\]"
    exit 1
}
foreach fn $argv {
    set direct($fn) 1
}
set mydir [info script].dir
rename source _source
proc source fn {
    if {![info exists ::direct($fn)]} {
	set fn $::mydir/[file tail $fn]
    }
    uplevel 1 [list _source $fn]
}

proc domset {x y} {wm title . $y}

set ::uniqEv 1
proc every {ms scr} {
    set fn every#$::uniqEv
    incr ::uniqEv
    proc $fn {} "after $ms $fn;uplevel #0 {$scr}"
    after 0 $fn
}

proc printf s {puts stderr $s}
    
source [lindex $argv 0]

Added nacl/tools/natcl2tk.dir/canv.natcl.





































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
# emu/canv.tcl: reimplement NaTcl's canv verbs in Tk
#

set width 578
set height 200

canvas .c -width $width -height $height -bg white
pack .c
update

proc canv_create {ty a b c args} {
    switch -exact -- $ty {
	circle {
	    set cc [list [expr {$a-$c}] [expr {$b-$c}] \
			[expr {$a+$c}] [expr {$b+$c}]]
	    set ty oval
	}
	default {
	    error "Unknown canv item type '$ty'"
	}
    }
    set it [eval .c create $ty $cc $args]
    set ::canvx($it) $a
    set ::canvy($it) $b
    return $it
}

proc canv_moveto {it x y} {
    set dx [expr {$x-$::canvx($it)}]
    set ::canvx($it) $x
    set dy [expr {$y-$::canvy($it)}]
    set ::canvy($it) $y
    .c move $it $dx $dy
}

proc canv_bind {evt cb} {
    switch -exact -- $evt {
	<Motion> {
	    bind .c <Motion> "$cb %x %y"
	}
	<Enter> - <Leave> {
	    bind .c $evt $cb
	}
	default {
	    error "Unknown canv event type '$evt'"
	}
    }
}