1
0
Fork 0
mirror of https://github.com/Reuh/ubiquitousse.git synced 2025-10-27 09:09:30 +00:00

Code reorganization, added uqt.ecs, removed LÖVE duplicates (uqt.audio, uqt.draw, uqt.filesystem)

This commit is contained in:
Étienne Fildadut 2019-12-24 19:05:50 +01:00
parent 523c5d36c0
commit 16e533d176
28 changed files with 2544 additions and 2107 deletions

123
init.lua
View file

@ -1,13 +1,45 @@
-- ubiquitousse
--- Ubiquitousse Game Engine.
-- Main module, containing the main things.
-- The API exposed here is the Ubiquitousse API.
-- It is as the name does not imply anymore abstract, and must be implemented in a backend, such as ubiquitousse.love.
-- When required, this file will try to autodetect the engine it is running on, and load a correct backend.
--- Ubiquitousse Game Framework.
-- Main module, which will try to load every other Ubiquitousse module when required and provide a few convenience functions.
--
-- Ubiquitousse may or may not be used as a full game engine. You can delete the modules files you don't need and Ubiquitousse
-- should adapt accordingly.
-- Ubiquitousse may or may not be used in its totality. You can delete the modules directories you don't need and Ubiquitousse
-- should adapt accordingly. You can also simply copy the modules directories you need and use them directly, without using this
-- file at all.
-- However, some modules may provide more feature when other modules are available.
-- These dependencies are written at the top of every main module file.
--
-- Ubiquitousse's goal is to run everywhere with the least porting effort possible, so Ubiquitousse tries to only use features that
-- are almost sure to be available everywhere.
--
-- Some Ubiquitousse modules require functions that are not in the Lua standard library, and must therefore be implemented in a backend,
-- such as ubiquitousse.love. When required, modules will try to autodetect the engine it is running on, and load a correct backend.
--
-- Most Ubiquitousse module backends require a few things to be fully implemented:
-- * The backend needs to have access to some kind of main loop, or at least a function called very often (may or may not be the
-- same as the redraw screen callback).
-- * Some way of measuring time (preferably with millisecond-precision).
-- * Some kind of filesystem.
-- * Lua 5.1, 5.2, 5.3 or LuaJit.
-- * Other requirement for specific modules should be described in the module's documentation.
--
-- Units used in the API documentation:
-- * All distances are expressed in pixels (px)
-- * All durations are expressed in milliseconds (ms)
-- These units are only used to make writing documentation easier; you can use other units if you want, as long as you're consistent.
--
-- Style:
-- * tabs for indentation, spaces for esthetic whitespace (notably in comments)
-- * no globals
-- * UPPERCASE for constants (or maybe not).
-- * CamelCase for class names.
-- * lowerCamelCase is expected for everything else.
--
-- Implementation levels:
-- * backend: nothing defined in Ubiquitousse, must be implemented in backend
-- * mixed: partly implemented in Ubiquitousse but must be complemeted in backend.
-- * ubiquitousse: fully-working version in Ubiquitousse, may or may not be redefined in backend
-- The implementation level is indicated using the "@impl level" annotation.
--
-- For backend writers:
-- If a function defined here already contains some code, this means this code is mandatory and you must put/call
@ -20,50 +52,8 @@
-- between the different versions, so it's up to you to handle that in your game (or ignore the problem and sticks to your
-- main's backend Lua version).
--
-- Ubiquitousse's goal is to run everywhere with the least porting effort possible.
-- To achieve this, the engine needs to stay simple, and only provide features that are almost sure to be
-- available everywhere, so writing a backend should be straighforward.
--
-- However, a full Ubiquitousse backend still have a few requirement about the destination platform:
-- * The backend needs to have access to some kind of main loop, or at least a function called very often (may or may not be the
-- same as the redraw screen callback).
-- * A 2D matrix graphic output with 32bit RGB color depth.
-- * Inputs which match ubiquitousse.input.default (a pointing/4 direction input, a confirm button, and a cancel button).
-- * Some way of measuring time with millisecond-precision.
-- * Some kind of filesystem.
-- * An available audio output would be preferable but optional.
-- * Lua 5.1, 5.2, 5.3 or LuaJit.
--
-- Regarding data formats, Ubiquitousse implementations expect and recommend:
-- * For images, PNG support is expected.
-- * For audio files, OGG Vorbis support is expected.
-- * For fonts, TTF support is expected.
-- Theses formats are respected for the reference implementations, but Ubiquitousse may provide a script to
-- automatically convert data formats from a project at some point.
--
-- Units used in the API:
-- * All distances are expressed in pixels (px)
-- * All durations are expressed in milliseconds (ms)
--
-- Style:
-- * tabs for indentation, spaces for esthetic whitespace (notably in comments)
-- * no globals
-- * UPPERCASE for constants (or maybe not).
-- * CamelCase for class names.
-- * lowerCamelCase is expected for everything else.
--
-- Implementation levels:
-- * backend: nothing defined in Ubiquitousse, must be implemented in backend
-- * mixed: partly implemented in Ubiquitousse but must be complemeted in backend
-- * ubiquitousse: fully-working version in Ubiquitousse, may or may not be redefined in backend
-- The implementation level is indicated using the "@impl level" annotation.
--
-- Some Ubiquitousse modules require parts of other modules to work. Because every module should work when all the others are
-- disabled, the backend may need to provide defaults values for a few fields in disabled modules required by an enabled one.
-- Thoses fields are indicated with "@requiredby module" annotations.
--
-- Regarding the documentation: Ubiquitousse used LDoc/LuaDoc styled-comments, but since LDoc hates me and my code, the
-- generated result is complete garbage, so please read the documentation directly in the comments here.
-- generated result is complete garbage, so please read the documentation directly in the comments here until fix this.
-- Stuff you're interested in starts with triple - (e.g., "--- This functions saves the world").
--
-- @usage local ubiquitousse = require("ubiquitousse")
@ -76,34 +66,31 @@ ubiquitousse = {
-- @impl ubiquitousse
version = "0.0.1",
--- Table of enabled modules.
-- @impl ubiquitousse
module = {
time = false,
draw = false,
audio = false,
input = false,
scene = false,
event = false,
asset = false,
util = false
},
--- Should be called each time the game loop is ran; will update every loaded Ubiquitousse module that needs it.
-- @tparam number dt time since last call, in miliseconds
-- @impl mixed
update = function(dt)
if ubiquitousse.time then ubiquitousse.time.update(dt) end
if ubiquitousse.scene then ubiquitousse.scene.update(dt) end
if ubiquitousse.input then ubiquitousse.input.update(dt) end
end,
--- Backend name.
-- For consistency, only use lowercase letters [a-z] (no special char)
-- @impl backend
backend = "unknown"
--- Should be called each time the game expect a new frame to be drawn; will draw every loaded Ubiquitousse module that needs it
-- The screen is expected to be cleared since last frame.
-- @impl mixed
draw = function()
if ubiquitousse.scene then ubiquitousse.scene.draw() end
end
}
-- We're going to require modules requiring Ubiquitousse, so to avoid stack overflows we already register the ubiquitousse package
package.loaded[p] = ubiquitousse
-- Require external submodules
for m in pairs(ubiquitousse.module) do
for _, m in ipairs{"asset", "ecs", "input", "scene", "time", "util"} do
local s, t = pcall(require, p.."."..m)
if s then
ubiquitousse[m] = t
ubiquitousse.module[m] = true
end
end