<div>could somebody gime me an advice about my very slow program ?</div><div>hello~ </div><div>it's 6 day passed since</div><div>I start making little game maker and emulator </div><div>I finally run very simple game (not a game but just map) today</div>
<div>but it is very very slow</div><div>perhaps there are something wrong ideas in structure of my program </div><div><br></div><div>could somebody give me an reason of slowness or fix my bad idea?</div><div>your little adive or related link would be very helpful for me </div>
<div>thanks in advanced </div><div><br></div><div>better show my code than explain it.</div><div><br></div><div>emulator===</div><div>#lang scheme</div><div>;requires and definitions</div><div>(require racket/gui)</div><div>
(require 2htdp/batch-io)</div><div>(define-namespace-anchor anchor)</div><div>(define ns (namespace-anchor->namespace anchor))</div><div>(define hero-map 0);map0 by default</div><div>(define hero-x 0)</div><div>(define hero-y 0)</div>
<div>(define base-dc (make-object bitmap-dc% (make-object bitmap% 320 320 #f)))</div><div><br></div><div>;function define</div><div>(define (eval-file path-string)</div><div> (define content (read-file path-string))</div>
<div> (define port (open-input-string content))</div><div> (read port)</div><div> (define (loop [exp (read port)])</div><div> (when (not (eof-object? exp))</div><div> (display exp) (eval exp ns) (loop (read port))))</div>
<div> (loop))</div><div><br></div><div>;class define</div><div>(define m-canvas% </div><div> (class canvas%</div><div> (override on-paint on-event)</div><div> (define on-event (λ (m) (when </div><div> (send m get-left-down) </div>
<div> (when (not (send god-input is-shown? )) (send pane add-child god-input)))))</div><div> (define on-paint </div><div> (λ () (send (send this get-dc) draw-bitmap (send base-dc get-bitmap) 0 0 )))</div>
<div> (super-new)))</div><div><br></div><div>(define f (new frame% (label "1")))</div><div><br></div><div>(define pane (new vertical-pane% (parent f)))</div><div>(define canvas (new m-canvas% (parent pane) (min-width 320) (min-height 320)))</div>
<div>(define user-input (new text-field% (parent pane) (label "input") (init-value "user-input")))</div><div>(define god-input (new text-field% (parent pane) (label "god-input")))</div><div>(send pane delete-child god-input)</div>
<div>(send f show #t)</div><div>;define objects ex: frame, vertical-pane, timer, canvas, user-input, god-input </div><div><br></div><div>;read map file and eval them(eval)(map file is consist of executable code)</div><div>
(define (eval-hero-map [map-num hero-map])</div><div> (if (file-exists? (string->path (format "./map~a.map" map-num)))</div><div> (eval-file (format "./map~a.map" map-num))</div><div> (message-box "fatal error" (format "can not find read-draw-loop.dat or map~a.map in current directory" map-num))))</div>
<div><br></div><div>;draw</div><div>(define (draw-tile #|map|# x y layer)</div><div> (define src-path (vector-ref (vector-ref (vector-ref (vector-ref (eval 'map0 ns) y) x) layer) 1))</div><div> (define src-x (vector-ref (vector-ref (vector-ref (vector-ref (eval 'map0 ns) y) x) layer) 2))</div>
<div> (define src-y (vector-ref (vector-ref (vector-ref (vector-ref (eval 'map0 ns) y) x) layer) 3))</div><div> (define as-bitmap (make-object bitmap% src-path))</div><div> (send base-dc draw-bitmap-section as-bitmap (* x 16) (* y 16) (* src-x 16) (* src-y 16) 16 16) </div>
<div> (send canvas on-paint)</div><div> )</div><div><br></div><div>(eval-hero-map)</div><div>(define (draw-tiles map)</div><div> (for* ([y (in-range 20)]</div><div> [x (in-range 20)])</div><div> (draw-tile #|map|# x y 0)))</div>
<div>(draw-tiles hero-map)</div><div> (send canvas on-paint)</div><div>=========</div><div><br></div><div>map===</div><div>(define width 20)</div><div>(define height 20)</div><div>#|when create a project, create map0 by default.|#</div>
<div>(define default-img "./src/main.png")</div><div>(define map0 </div><div> (make-vector height #|y-container|#</div><div> (make-vector width #|x-container|#</div><div> (make-vector 16 #|each tile container. can contain 16 layers|#</div>
<div> (vector 8</div><div> default-img </div><div> 4 #|x |#</div><div> 15 #|y|#</div>
<div> #t </div><div> "none" #|can be "(and (touch?) (equal? (key) "left"))" => #t or #f|#</div>
<div> "none" #|can be (level-up) etc..|#</div><div> (make-hash (list '(a 0) #|can be customized hash,could be as a->hole 0->100|#</div>
<div> '(b 0)</div><div> '(c 0)</div><div> '(d 0)</div>
<div> '(f 0)</div><div> '(g 0)</div><div> '(g 0)</div>
<div> '(h 0)</div><div> '(i 0)</div><div> '(j 0)))</div>
<div> #f #|show?|#</div><div> )) </div><div> </div><div> )))</div><div>
=======</div><div><br></div>