From e43287a8185702b52a591afb3ade81ca8e383f25 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 27 Dec 2019 18:05:32 +0100 Subject: [PATCH] dimension2d as a foreign record type --- examples/01.HelloWorld.scm | 2 +- examples/02.Quake3Map.scm | 2 +- irrlicht.scm | 1 + irrlicht/bindings/core.scm | 30 +++++++++++++++--------------- irrlicht/device.scm | 3 +-- irrlicht/dimension2d.scm | 35 +++++++++++++++++++++++++++++++++++ irrlicht/util.scm | 11 ++--------- 7 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 irrlicht/dimension2d.scm diff --git a/examples/01.HelloWorld.scm b/examples/01.HelloWorld.scm index 3f128cb..40b0aca 100644 --- a/examples/01.HelloWorld.scm +++ b/examples/01.HelloWorld.scm @@ -28,7 +28,7 @@ (define device (create-device #:device-type 'software - #:window-size '(640 480))) + #:window-size (make-dimension2d 640 480))) (when (not device) (exit #f)) diff --git a/examples/02.Quake3Map.scm b/examples/02.Quake3Map.scm index 45249ac..5f26f2a 100644 --- a/examples/02.Quake3Map.scm +++ b/examples/02.Quake3Map.scm @@ -52,7 +52,7 @@ (define device (create-device #:device-type driver - #:window-size '(640 480))) + #:window-size (make-dimension2d 640 480))) (when (not device) (exit #f)) diff --git a/irrlicht.scm b/irrlicht.scm index aaa58ea..c70a122 100644 --- a/irrlicht.scm +++ b/irrlicht.scm @@ -25,6 +25,7 @@ (let ((public-modules '((irrlicht aabbox3d) (irrlicht device) + (irrlicht dimension2d) (irrlicht gui) (irrlicht io) (irrlicht scene) diff --git a/irrlicht/bindings/core.scm b/irrlicht/bindings/core.scm index c432714..8605919 100644 --- a/irrlicht/bindings/core.scm +++ b/irrlicht/bindings/core.scm @@ -22,11 +22,23 @@ #:use-module (system foreign) #:use-module (irrlicht util)) +;; rect struct +(define-public rect + (list int32 int32 int32 int32)) + +;; vector2df struct +(define-public vector2df + (list float float float)) + +;; vector3df struct +(define-public vector3df + (list float float float)) + ;; aabbox3d f32 struct and functions (define-public aabbox3d_f32 - (list - float float float ;minEdge - float float float ;maxEdge + (append + vector3df ; min-edge + vector3df ; max-edge )) (define-foreign aabbox3d-add-internal-point @@ -34,15 +46,3 @@ (define-foreign aabbox3d-reset void "irr_core_aabbox3d_reset" (list '* '*)) - -;; dimension2d struct -(define-public dimension2d - (list uint32 uint32)) - -;; rect struct -(define-public rect - (list int32 int32 int32 int32)) - -;; vector3df struct -(define-public vector3df - (list float float float)) diff --git a/irrlicht/device.scm b/irrlicht/device.scm index 928a6c8..25ec8ca 100644 --- a/irrlicht/device.scm +++ b/irrlicht/device.scm @@ -22,7 +22,6 @@ #:use-module (ice-9 match) #:use-module (system foreign) #:use-module ((irrlicht bindings) #:prefix ffi:) - #:use-module ((irrlicht bindings core) #:prefix ffi-core:) #:use-module ((irrlicht bindings video) #:prefix ffi-video:) #:use-module (irrlicht util) #:export (create-device @@ -51,7 +50,7 @@ ('direct3d9 ffi-video:EDT_DIRECT3D9) ('opengl ffi-video:EDT_OPENGL) ('count ffi-video:EDT_COUNT))) - (wsize (make-c-struct ffi-core:dimension2d window-size))) + (wsize (foreign-record-pointer window-size))) (let ((device (ffi:create-device driver wsize bits (bool->integer fullscreen) (bool->integer stencilbuffer) diff --git a/irrlicht/dimension2d.scm b/irrlicht/dimension2d.scm new file mode 100644 index 0000000..7eb8cfd --- /dev/null +++ b/irrlicht/dimension2d.scm @@ -0,0 +1,35 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +(define-module (irrlicht dimension2d) + #:use-module (system foreign) + #:use-module (irrlicht util) + #:export (dimension2d + make-dimension2d + dimension2d? + dimension2d-width + dimension2d-height)) + +;; dimension2d struct +(define-foreign-record-type dimension2d + (make-dimension2d width height) + dimension2d? + (width uint32 dimension2d-width) + (height uint32 dimension2d-height)) diff --git a/irrlicht/util.scm b/irrlicht/util.scm index 488ea33..9110be9 100644 --- a/irrlicht/util.scm +++ b/irrlicht/util.scm @@ -26,7 +26,8 @@ #:export (bool->integer integer->bool define-foreign - define-foreign-record-type)) + define-foreign-record-type + foreign-record-pointer)) (define (bool->integer var) (if var 1 0)) @@ -147,12 +148,4 @@ (list-set! values setter-id new-value) (set-foreign-record-pointer! record (make-c-struct types values)) new-value)) - ... - - (export name) - (export make-name) - (export predicate?) - (export getter) - ... - (export setter) ...)))))) -- 2.39.2