From 3b22fd3f425de9419f98bacf2d1c4675058389ed Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Thu, 17 Apr 2014 11:55:55 +0200 Subject: [PATCH] Preparing skeleton for engines, systems, etc * engines/arcade.scm: First engine for developing arcade games * examples/asteroids.scm: Asteroids game, with two ways of make a game * game.scm: New structure that contains the engine and all the entities with their initial state * systems/opengl.scm: First system for displaying entities using opengl libraries --- src/engines/arcade.scm | 19 +++++++++ src/examples/asteroids.scm | 32 ++++++++++++++ src/game.scm | 85 ++++++++++++++++++++++++++++++++++++++ src/systems/opengl.scm | 31 ++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 src/engines/arcade.scm create mode 100644 src/examples/asteroids.scm create mode 100644 src/game.scm create mode 100644 src/systems/opengl.scm diff --git a/src/engines/arcade.scm b/src/engines/arcade.scm new file mode 100644 index 0000000..5d1e429 --- /dev/null +++ b/src/engines/arcade.scm @@ -0,0 +1,19 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2014 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program 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 General Public License +;;; along with this program. If not, see . + + +(define-module (gacela engines arcade) + #:use-module (gacela engine)) diff --git a/src/examples/asteroids.scm b/src/examples/asteroids.scm new file mode 100644 index 0000000..ff607f4 --- /dev/null +++ b/src/examples/asteroids.scm @@ -0,0 +1,32 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2014 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program 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 General Public License +;;; along with this program. If not, see . + + +(define-module (gacela examples asteroids) + #:use-module (gacela game)) + + +(define asteroids (make-game "Asteroids")) +(define player (make-entity)) +(add-component player (make-transform)) +(add-component player (make-mesh)) +(add-entity asteroids player) + +(define asteroids + (make-game "Asteroids" + (make-entity + (make-transform) + (make-mesh)))) diff --git a/src/game.scm b/src/game.scm new file mode 100644 index 0000000..5a8b7d3 --- /dev/null +++ b/src/game.scm @@ -0,0 +1,85 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2014 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program 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 General Public License +;;; along with this program. If not, see . + + +(define-module (gacela game) + #:use-module (gacela engine) + #:use-module (ice-9 vlist) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-9 gnu)) + + +;;; Working with entities + +(define-record-type entity + (make-entity-record id components) + entity? + (id entity-id) + (components entity-components set-entity-components!)) + +(set-record-type-printer! entity + (lambda (record port) + (format port "#<[entity ~a] ~a>" + (entity-id record) + (entity-components record)))) + +(define (make-entity . components) + (make-entity-record + (gensym) + components)) + +(export make-entity + entity? + entity-id) + + +;;; Game Definition + +(define-record-type game + (make-game-record name entities) + game? + (name game-name set-game-name!) + (entities game-entities set-game-entities!)) + +(set-record-type-printer! game + (lambda (record port) + (format port "#<[Game: ~a] ~a>" + (game-name record) + (map + (lambda (id) + (cdr (vhash-assoc id (game-entities record)))) + (vhash-fold + (lambda (key value result) + (lset-union eqv? (list key) result)) + '() + (game-entities record)))))) + +(define (make-game name . entities) + (make-game-record + name + (alist->vhash + (map (lambda (e) (cons (entity-id e) e)) + entities)))) + +(export make-game + game?) + + +;;; Working with games + +(define (add-entity game entity) + #f) diff --git a/src/systems/opengl.scm b/src/systems/opengl.scm new file mode 100644 index 0000000..0b96525 --- /dev/null +++ b/src/systems/opengl.scm @@ -0,0 +1,31 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2013 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program 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 General Public License +;;; along with this program. If not, see . + + +(define-module (gacela systems opengl) + #:use-module (figl gl) + #:use-module (figl glu) + #:use-module (figl glut) + #:use-module (gacela system)) + +(define-component opengl-window title #:optional window-handle) + +(define-system windows-manager ((windows (window-handle))) + (display windows) + (newline)) + +(export-component opengl-window) +(export windows-manager) -- 2.39.2