[racket] could somebody gime me an advice about my very slow program ?

From: 김태윤 (kty1104 at gmail.com)
Date: Thu Nov 18 01:18:17 EST 2010

could somebody gime me an advice about my very slow program ?
it's 6 day passed since
I start making little game maker and emulator
I finally run very simple game (not a game but just map) today
but it is very very slow
perhaps there are something wrong ideas in structure of my program

could somebody give me an reason of slowness or fix my bad idea?
your little adive or related link would be very helpful for me
thanks in advanced

better show my code than explain it.

#lang scheme
;requires and definitions
(require racket/gui)
(require 2htdp/batch-io)
(define-namespace-anchor anchor)
(define ns (namespace-anchor->namespace anchor))
(define hero-map 0);map0 by default
(define hero-x 0)
(define hero-y 0)
(define base-dc (make-object bitmap-dc% (make-object bitmap% 320 320 #f)))

;function define
(define (eval-file path-string)
  (define content (read-file path-string))
  (define port (open-input-string content))
  (read port)
  (define (loop [exp (read port)])
    (when (not (eof-object? exp))
       (display exp) (eval exp ns) (loop (read port))))

;class define
(define m-canvas%
  (class canvas%
    (override on-paint on-event)
    (define on-event (λ (m) (when
                                (send m get-left-down)
                              (when (not (send god-input is-shown? )) (send
pane add-child god-input)))))
    (define on-paint
      (λ () (send (send this get-dc) draw-bitmap (send base-dc get-bitmap) 0
0 )))

(define f (new frame% (label "1")))

(define pane (new vertical-pane% (parent f)))
(define canvas (new m-canvas% (parent pane) (min-width 320) (min-height
(define user-input (new text-field% (parent pane) (label "input")
(init-value "user-input")))
(define god-input (new text-field% (parent pane) (label "god-input")))
(send pane delete-child god-input)
(send f show #t)
;define objects ex: frame, vertical-pane, timer, canvas, user-input,

;read map file and eval them(eval)(map file is consist of executable code)
(define (eval-hero-map [map-num hero-map])
  (if (file-exists? (string->path (format "./map~a.map" map-num)))
      (eval-file (format "./map~a.map" map-num))
      (message-box "fatal error" (format "can not find read-draw-loop.dat or
map~a.map in current directory" map-num))))

(define (draw-tile #|map|# x y layer)
  (define src-path (vector-ref (vector-ref (vector-ref (vector-ref (eval
'map0 ns) y) x) layer) 1))
  (define src-x (vector-ref (vector-ref (vector-ref (vector-ref (eval 'map0
ns) y) x) layer) 2))
  (define src-y (vector-ref (vector-ref (vector-ref (vector-ref (eval 'map0
ns) y) x) layer) 3))
  (define as-bitmap (make-object bitmap% src-path))
  (send base-dc draw-bitmap-section as-bitmap (* x 16) (* y 16) (* src-x 16)
(* src-y 16) 16 16)
  (send canvas on-paint)

(define (draw-tiles map)
  (for* ([y (in-range 20)]
         [x (in-range 20)])
  (draw-tile #|map|# x y 0)))
(draw-tiles hero-map)
 (send canvas on-paint)

(define width 20)
(define height 20)
#|when create a project, create map0 by default.|#
(define default-img "./src/main.png")
(define map0
  (make-vector height #|y-container|#
               (make-vector width #|x-container|#
                            (make-vector 16 #|each tile container. can
contain 16 layers|#
                                         (vector 8
                                                 4 #|x |#
                                                 15 #|y|#
                                                 "none" #|can be "(and
(touch?) (equal? (key) "left"))" => #t or #f|#
                                                 "none" #|can be (level-up)
                                                 (make-hash (list '(a 0)
#|can be customized hash,could be as a->hole 0->100|#
                                                            '(b 0)
                                                            '(c 0)
                                                            '(d 0)
                                                            '(f 0)
                                                            '(g 0)
                                                            '(g 0)
                                                            '(h 0)
                                                            '(i 0)
                                                            '(j 0)))
                                                 #f #|show?|#

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101118/7f494f96/attachment.html>

Posted on the users mailing list.