From d8367430b147ccdb2505295a7d50f1f412b4e6e1 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 11 Nov 2019 09:48:45 +0100 Subject: [PATCH] Boolean functions --- irrlicht/device.scm | 13 +++++++------ irrlicht/gui.scm | 9 +++++---- irrlicht/io.scm | 5 +++-- irrlicht/scene.scm | 15 ++++++++------- irrlicht/util.scm | 29 +++++++++++++++++++++++++++++ irrlicht/video.scm | 5 +++-- 6 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 irrlicht/util.scm diff --git a/irrlicht/device.scm b/irrlicht/device.scm index 9a009ef..928a6c8 100644 --- a/irrlicht/device.scm +++ b/irrlicht/device.scm @@ -24,6 +24,7 @@ #: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 get-cursor-control get-file-system @@ -52,9 +53,9 @@ ('count ffi-video:EDT_COUNT))) (wsize (make-c-struct ffi-core:dimension2d window-size))) (let ((device (ffi:create-device driver wsize bits - (if fullscreen 1 0) - (if stencilbuffer 1 0) - (if vsync 1 0)))) + (bool->integer fullscreen) + (bool->integer stencilbuffer) + (bool->integer vsync)))) (if (null-pointer? device) #f device)))) (define (get-cursor-control device) @@ -73,13 +74,13 @@ (ffi:get-scene-manager device)) (define (is-window-active? device) - (if (> (ffi:is-window-active device) 0) #t #f)) + (integer->bool (ffi:is-window-active device))) (define (set-window-caption! device text) (ffi:set-window-caption device (string->pointer text))) (define (device-run? device) - (if (> (ffi:run device) 0) #t #f)) + (integer->bool (ffi:run device))) (define (device-drop! device) - (if (> (ffi:drop device) 0) #t #f)) + (integer->bool (ffi:drop device))) diff --git a/irrlicht/gui.scm b/irrlicht/gui.scm index 641cf47..0910269 100644 --- a/irrlicht/gui.scm +++ b/irrlicht/gui.scm @@ -23,6 +23,7 @@ #:use-module (system foreign) #:use-module ((irrlicht bindings core) #:prefix ffi-core:) #:use-module ((irrlicht bindings gui) #:prefix ffi-gui:) + #:use-module (irrlicht util) #:export (add-static-text! gui-draw-all set-visible-cursor!)) @@ -37,11 +38,11 @@ (ffi-gui:add-static-text gui-env (string->pointer text) (make-c-struct ffi-core:rect rectangle) - (if border 1 0) - (if word-wrap 1 0) + (bool->integer border) + (bool->integer word-wrap) parent id - (if fill-background 1 0))) + (bool->integer fill-background))) (define (gui-draw-all gui-env) (ffi-gui:draw-all gui-env)) @@ -49,4 +50,4 @@ (define (set-visible-cursor! cursor-control visible) (ffi-gui:set-visible-cursor cursor-control - (if visible 1 0))) + (bool->integer visible))) diff --git a/irrlicht/io.scm b/irrlicht/io.scm index 13288d5..9aaf34c 100644 --- a/irrlicht/io.scm +++ b/irrlicht/io.scm @@ -22,6 +22,7 @@ #:use-module (ice-9 match) #:use-module (system foreign) #:use-module ((irrlicht bindings io) #:prefix ffi-io:) + #:use-module (irrlicht util) #:export (add-file-archive!)) (define* (add-file-archive! file-system filename @@ -42,8 +43,8 @@ ('unknown ffi-io:EFAT_UNKNOWN)))) (ffi-io:add-file-archive file-system (string->pointer filename) - (if ignore-case 1 0) - (if ignore-paths 1 0) + (bool->integer ignore-case) + (bool->integer ignore-paths) type (string->pointer password) ret-archive))) diff --git a/irrlicht/scene.scm b/irrlicht/scene.scm index 8c622ef..264a4bd 100644 --- a/irrlicht/scene.scm +++ b/irrlicht/scene.scm @@ -24,6 +24,7 @@ #:use-module ((irrlicht bindings core) #:prefix ffi-core:) #:use-module ((irrlicht bindings scene) #:prefix ffi-scene:) #:use-module ((irrlicht bindings video) #:prefix ffi-video:) + #:use-module (irrlicht util) #:export (add-animated-mesh-scene-node add-camera-scene-node add-camera-scene-node-fps! @@ -51,7 +52,7 @@ (make-c-struct ffi-core:vector3df position) (make-c-struct ffi-core:vector3df rotation) (make-c-struct ffi-core:vector3df scale) - (if also-add-if-mesh-pointer-zero 1 0)))) + (bool->integer also-add-if-mesh-pointer-zero)))) (if (null-pointer? node) #f node))) (define* (add-camera-scene-node scene-manager @@ -67,7 +68,7 @@ (make-c-struct ffi-core:vector3df position) (make-c-struct ffi-core:vector3df lookat) id - (if make-active 1 0)))) + (bool->integer make-active)))) (if (null-pointer? camera) #f camera))) (define* (add-camera-scene-node-fps! scene-manager @@ -90,10 +91,10 @@ id key-map-array key-map-size - (if no-vertical-movement 1 0) + (bool->integer no-vertical-movement) jump-speed - (if invert-mouse 1 0) - (if make-active 1 0))) + (bool->integer invert-mouse) + (bool->integer make-active))) (define* (add-octree-scene-node-am scene-manager mesh #:key @@ -107,7 +108,7 @@ parent id minimal-polys-per-node - (if also-add-if-mesh-pointer-zero 1 0))) + (bool->integer also-add-if-mesh-pointer-zero))) (define (get-mesh scene-manager filename) (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename)))) @@ -142,7 +143,7 @@ (ffi-scene:set-material-flag-am node material-flag - (if newvalue 1 0)))) + (bool->integer newvalue)))) (define (set-material-texture-am! node texture-layer texture) (ffi-scene:set-material-texture-am node texture-layer texture)) diff --git a/irrlicht/util.scm b/irrlicht/util.scm new file mode 100644 index 0000000..8c5b9e4 --- /dev/null +++ b/irrlicht/util.scm @@ -0,0 +1,29 @@ +;;; 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 util) + #:export (bool->integer + integer->bool)) + +(define (bool->integer var) + (if var 1 0)) + +(define (integer->bool var) + (if (= var 0) #f #t)) diff --git a/irrlicht/video.scm b/irrlicht/video.scm index e113815..000373d 100644 --- a/irrlicht/video.scm +++ b/irrlicht/video.scm @@ -22,6 +22,7 @@ #:use-module (system foreign) #:use-module ((irrlicht bindings core) #:prefix ffi-core:) #:use-module ((irrlicht bindings video) #:prefix ffi-video:) + #:use-module (irrlicht util) #:export (begin-scene end-scene get-fps @@ -36,8 +37,8 @@ (video-data %null-pointer) (source-rect '())) (ffi-video:begin-scene driver - (if back-buffer 1 0) - (if z-buffer 1 0) + (bool->integer back-buffer) + (bool->integer z-buffer) (make-c-struct ffi-video:scolor color) video-data (if (null? source-rect) -- 2.39.2