Select Git revision
parse-map.scm
parse-map.scm 7.78 KiB
;;; Commentary
;; This is a parser for the Wolfenstein 3d mapdata
;; It should work with both the shareware and full version, as well as Spear of
;; Destiny. It requires that the files are Carmack-compressed.
;; Procedures is as far as possible anotated with where in which file they
;; originated from. The original Wolf3D source can be found at:
;; https://github.com/id-Software/wolf3d
;;; Code
(use-modules (ice-9 format)
((rnrs base) #:select (assert))
(rnrs io ports)
(rnrs bytevectors)
(srfi srfi-1)
(srfi srfi-4) ; u16vector-ref
((srfi srfi-9) #:select (define-record-type))
((srfi srfi-9 gnu) #:select (set-record-type-printer!))
)
;; Util
(define (hex a)
(format #f "~:@(~4,'0x~)" a))
(define (cross-product l1 l2)
(concatenate
(map (lambda (a)
(map (lambda (b) (list a b))
l2))
l1)))
;; Displays a 2d array, representing 0 as a space and everything else as an octophorpe
(define (display-tilemap tilemap)
(format #t "~{|~{~[ ~:;#~]~}|~%~}"
(array->list tilemap)))
(define-syntax ->
(syntax-rules ()
((-> obj)
obj)
((-> obj (func args ...) rest ...)
(-> (func obj args ...) rest ...))
((-> obj func rest ...)
(-> (func obj) rest ...))))
(define* (bytevector->c-string
bv #:key (transcoder (make-transcoder "ASCII")))
(string-trim-right (bytevector->string bv transcoder)
#\nul))
;; Constants
(define MAPPLANES 2)
(define AREATILE 107)
;; Datatypes
;; @example