Unverified Commit 2c463256 authored by Rob Loach's avatar Rob Loach
Browse files

Merge branch 'master' of github.com:libretro/libretro-lutro into luasocket

Conflicts:
	Makefile.common
parents 9b647903 9f8464d6
......@@ -2,6 +2,7 @@ HAVE_INOTIFY=0
HAVE_COMPOSITION=0
WANT_JIT=0
WANT_ZLIB=1
WANT_UNZIP=1
MMD := -MMD
......@@ -53,7 +54,7 @@ ifeq ($(platform), unix)
SHARED := -shared -Wl,--no-as-needed,--no-undefined
LUA_SYSCFLAGS := -DLUA_USE_POSIX
HAVE_INOTIFY=1
LDFLAGS += -Wl,-E -pthread
LDFLAGS += -Wl,-E
ifeq ($(ARCH), $(filter $(ARCH), intel))
WANT_JIT = 1
......@@ -185,7 +186,7 @@ else ifeq ($(platform), sncps3)
MMD :=
else
CC = gcc
TARGET := $(TARGET_NAME)_retro.dll
TARGET := $(TARGET_NAME)_libretro.dll
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--no-undefined
endif
......@@ -214,7 +215,7 @@ ifeq ($(WANT_JIT),1)
CFLAGS += -DHAVE_JIT
endif
CFLAGS += -I$(LUADIR) $(DEFINES)
CFLAGS += -I$(LUADIR) $(DEFINES) -DOUTSIDE_SPEEX -DRANDOM_PREFIX=speex -DEXPORT= -DFIXED_POINT
LIBS += $(LUALIB) $(LIBM)
......@@ -254,7 +255,7 @@ else
endif
deps/lua/src/liblua.a:
$(MAKE) -C deps/lua/src CC="$(CC)" CXX="$(CXX)" MYCFLAGS="$(LUA_MYCFLAGS) -w -g $(fpic)" MYLDFLAGS="$(LFLAGS) $(fpic)" SYSCFLAGS="$(LUA_SYSCFLAGS) $(fpic)" a
$(MAKE) -C deps/lua/src CC="$(CC)" CXX="$(CXX)" MYCFLAGS="$(LUA_MYCFLAGS) -w -g $(fpic)" MYLDFLAGS="$(LFLAGS) $(fpic)" SYSCFLAGS="$(LUA_SYSCFLAGS) $(fpic)" generic
deps/luajit/src/libluajit.a:
$(MAKE) -C deps/luajit/src BUILDMODE=static CFLAGS="$(LUA_MYCFLAGS) $(fpic)" Q= LDFLAGS="$(fpic)"
......
LUALIB_DIR := $(CORE_DIR)/deps/lua/src
INCFLAGS := -I$(CORE_DIR) \
-I$(CORE_DIR)/libretro-common/include \
-I$(CORE_DIR)/deps/zlib \
-I$(CORE_DIR)/deps
-I$(CORE_DIR)/deps/retroluxury/src \
-I$(CORE_DIR)/deps \
-I$(LUALIB_DIR)
SOURCES_C := $(CORE_DIR)/libretro.c \
$(CORE_DIR)/lutro.c \
$(CORE_DIR)/runtime.c \
$(CORE_DIR)/image.c \
$(CORE_DIR)/graphics.c \
$(CORE_DIR)/input.c \
$(CORE_DIR)/audio.c \
$(CORE_DIR)/event.c \
$(CORE_DIR)/keyboard.c \
$(CORE_DIR)/sound.c \
$(CORE_DIR)/filesystem.c \
$(CORE_DIR)/system.c \
$(CORE_DIR)/timer.c \
$(CORE_DIR)/lutro_math.c \
$(CORE_DIR)/joystick.c \
$(CORE_DIR)/mouse.c \
$(CORE_DIR)/window.c \
$(CORE_DIR)/painter.c
SOURCES_C += $(CORE_DIR)/libretro.c \
$(CORE_DIR)/lutro.c \
$(CORE_DIR)/runtime.c \
$(CORE_DIR)/image.c \
$(CORE_DIR)/graphics.c \
$(CORE_DIR)/input.c \
$(CORE_DIR)/audio.c \
$(CORE_DIR)/event.c \
$(CORE_DIR)/keyboard.c \
$(CORE_DIR)/sound.c \
$(CORE_DIR)/filesystem.c \
$(CORE_DIR)/system.c \
$(CORE_DIR)/timer.c \
$(CORE_DIR)/lutro_math.c \
$(CORE_DIR)/joystick.c \
$(CORE_DIR)/mouse.c \
$(CORE_DIR)/window.c \
$(CORE_DIR)/painter.c
ifeq ($(WANT_LUALIB),1)
SOURCES_C += $(LUALIB_DIR)/lapi.c \
$(LUALIB_DIR)/lauxlib.c \
$(LUALIB_DIR)/lbaselib.c \
$(LUALIB_DIR)/lcode.c \
$(LUALIB_DIR)/ldblib.c \
$(LUALIB_DIR)/ldo.c \
$(LUALIB_DIR)/lfunc.c \
$(LUALIB_DIR)/lgc.c \
$(LUALIB_DIR)/linit.c \
$(LUALIB_DIR)/liolib.c \
$(LUALIB_DIR)/llex.c \
$(LUALIB_DIR)/lmathlib.c \
$(LUALIB_DIR)/lmem.c \
$(LUALIB_DIR)/loadlib.c \
$(LUALIB_DIR)/lobject.c \
$(LUALIB_DIR)/lopcodes.c \
$(LUALIB_DIR)/loslib.c \
$(LUALIB_DIR)/lparser.c \
$(LUALIB_DIR)/lstate.c \
$(LUALIB_DIR)/lstring.c \
$(LUALIB_DIR)/lstrlib.c \
$(LUALIB_DIR)/ltable.c \
$(LUALIB_DIR)/ltablib.c \
$(LUALIB_DIR)/ltm.c \
$(LUALIB_DIR)/lua.c \
$(LUALIB_DIR)/lvm.c \
$(LUALIB_DIR)/lzio.c \
$(LUALIB_DIR)/ldebug.c \
$(LUALIB_DIR)/lundump.c \
$(LUALIB_DIR)/ldump.c
endif
SOURCES_C += $(CORE_DIR)/deps/retroluxury/src/external/resample.c \
$(CORE_DIR)/deps/retroluxury/src/rl_resample.c \
$(CORE_DIR)/deps/retroluxury/src/rl_sound.c \
$(CORE_DIR)/deps/retroluxury/src/rl_snddata.c
SOURCES_C += $(CORE_DIR)/libretro-common/formats/png/rpng_decode.c \
$(CORE_DIR)/libretro-common/formats/png/rpng_fbio.c \
$(CORE_DIR)/libretro-common/file/file_path.c \
$(CORE_DIR)/libretro-common/compat/compat.c \
$(CORE_DIR)/libretro-common/rthreads/rthreads.c
$(CORE_DIR)/libretro-common/compat/compat.c
# Lua UTF-8
SOURCES_C += $(CORE_DIR)/deps/luautf8/lutf8lib.c
......@@ -52,6 +94,10 @@ else
SOURCES_C += $(CORE_DIR)/deps/luasocket/libluasocket/wsocket.c
endif
ifeq ($(WANT_UNZIP),1)
SOURCES_C += $(CORE_DIR)/deps/zlib/ioapi.c \
$(CORE_DIR)/deps/zlib/unzip.c
endif
ifeq ($(WANT_ZLIB),1)
SOURCES_C += $(CORE_DIR)/deps/zlib/adler32.c \
......@@ -67,9 +113,7 @@ SOURCES_C += $(CORE_DIR)/deps/zlib/adler32.c \
$(CORE_DIR)/deps/zlib/inftrees.c \
$(CORE_DIR)/deps/zlib/trees.c \
$(CORE_DIR)/deps/zlib/uncompr.c \
$(CORE_DIR)/deps/zlib/zutil.c \
$(CORE_DIR)/deps/zlib/ioapi.c \
$(CORE_DIR)/deps/zlib/unzip.c
$(CORE_DIR)/deps/zlib/zutil.c
endif
ifeq ($(HAVE_INOTIFY),1)
......
......@@ -2,11 +2,10 @@
Experimental [Lua](http://lua.org) game framework for [libretro](http://libretro.com), following the [LÖVE](http://love2d.org) API.
Lutro is software rendered and implements only a subset of the LÖVE API. It targets portability though the libretro API and backed in dependancies.
[Lutro](https://github.com/libretro/libretro-lutro) is software rendered and implements only a [subset of the LÖVE API](https://github.com/libretro/lutro-status). It targets portability though the libretro API and backed in dependancies.
## Sample Games
* https://github.com/libretro/lutro-platformer
* https://github.com/libretro/lutro-game-of-life
* https://github.com/libretro/lutro-snake
......
#include "audio.h"
#include "lutro.h"
#include "compat/strl.h"
#include "rthreads/rthreads.h"
#include <stdlib.h>
#include <string.h>
/* TODO/FIXME - no sound on big-endian */
static audio_Source** sources = NULL;
static size_t sources_count = 0;
static size_t sources_allocated = 0;
static slock_t* sources_lock = NULL;
static unsigned num_sources = 0;
static audio_Source** sources = NULL;
static float volume = 1.0;
static void add_source(audio_Source *src)
{
slock_lock(sources_lock);
if (sources_count == sources_allocated)
{
size_t new_size = (sources_allocated + 1) * 2;
sources = (audio_Source**)realloc(sources, new_size * sizeof(audio_Source*));
memset(&sources[sources_allocated], 0, (new_size - sources_allocated) * sizeof(audio_Source*));
sources_allocated = new_size;
}
sources[sources_count++] = src;
slock_unlock(sources_lock);
}
static void remove_source(const audio_Source *src)
{
unsigned i;
slock_lock(sources_lock);
for (i = 0; i < sources_count; ++i)
{
if (sources[i] == src)
{
memmove(&sources[i], sources[i+1], (sources_count-i-1) * sizeof(audio_Source*));
sources_count--;
break;
}
}
slock_unlock(sources_lock);
}
void mixer_render(int16_t *buffer)
{
uint8_t* rawsamples8 = NULL;
size_t rawsamples8_bps = 0;
// Clear buffer
memset(buffer, 0, AUDIO_FRAMES * 2 * sizeof(int16_t));
/* Audio subsystem not ready */
if (!sources_count || !sources)
return;
slock_lock(sources_lock);
// Loop over audio sources
for (unsigned i = 0; i < sources_count; i++)
for (unsigned i = 0; i < num_sources; i++)
{
if (sources[i]->state == AUDIO_STOPPED)
continue;
if (sources[i]->bps > rawsamples8_bps)
{
rawsamples8_bps = sources[i]->bps;
rawsamples8 = realloc(rawsamples8, rawsamples8_bps * AUDIO_FRAMES);
memset(rawsamples8, 0, rawsamples8_bps * AUDIO_FRAMES);
}
uint8_t* rawsamples8 = calloc(
AUDIO_FRAMES * sources[i]->bps, sizeof(uint8_t));
bool end = ! fread(rawsamples8,
sizeof(uint8_t),
......@@ -105,12 +51,8 @@ void mixer_render(int16_t *buffer)
fseek(sources[i]->sndta.fp, WAV_HEADER_SIZE, SEEK_SET);
}
}
if (rawsamples8)
free(rawsamples8);
slock_unlock(sources_lock);
}
}
int lutro_audio_preload(lua_State *L)
......@@ -135,28 +77,15 @@ int lutro_audio_preload(lua_State *L)
void lutro_audio_init()
{
sources_lock = slock_new();
}
void lutro_audio_deinit()
{
if (sources_lock)
slock_lock(sources_lock);
if (sources)
free(sources);
sources = NULL;
sources_count = 0;
sources_allocated = 0;
if (sources_lock)
{
slock_t *tmp = sources_lock;
sources_lock = NULL;
slock_unlock(tmp);
slock_free(tmp);
free(sources);
sources = NULL;
num_sources = 0;
}
}
......@@ -197,7 +126,9 @@ int audio_newSource(lua_State *L)
self->state = AUDIO_STOPPED;
fseek(self->sndta.fp, 0, SEEK_END);
add_source(self);
num_sources++;
sources = (audio_Source**)realloc(sources, num_sources * sizeof(audio_Source));
sources[num_sources-1] = self;
if (luaL_newmetatable(L, "Source") != 0)
{
......@@ -335,16 +266,7 @@ int source_getPitch(lua_State *L)
int source_gc(lua_State *L)
{
audio_Source* self = (audio_Source*)luaL_checkudata(L, 1, "Source");
remove_source(self);
self->state = AUDIO_STOPPED;
/* TODO: do this at SoundData's gc method */
if (self->sndta.fp)
fclose(self->sndta.fp);
self->sndta.fp = NULL;
(void)self;
return 0;
}
......
......@@ -8,7 +8,7 @@
PLAT= none
CC= gcc
CFLAGS= -O2 -Wall $(MYCFLAGS)
CFLAGS= -O2 -Wall -fPIC $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
......
......@@ -178,9 +178,13 @@ static void buffreplace (LexState *ls, char from, char to) {
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* format error: try to update decimal point separator */
struct lconv *cv = localeconv();
char old = ls->decpoint;
#ifdef ANDROID
ls->decpoint = '.';
#else
struct lconv *cv = localeconv();
ls->decpoint = (cv ? cv->decimal_point[0] : '.');
#endif
buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
/* format error with correct decimal point: no more options */
......
/*
** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
*/
#include <ctype.h>
#include <stdio.h>
#define luac_c
#define LUA_CORE
#include "ldebug.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lundump.h"
#define PrintFunction luaU_print
#define Sizeof(x) ((int)sizeof(x))
#define VOID(p) ((const void*)(p))
static void PrintString(const TString* ts)
{
const char* s=getstr(ts);
size_t i,n=ts->tsv.len;
putchar('"');
for (i=0; i<n; i++)
{
int c=s[i];
switch (c)
{
case '"': printf("\\\""); break;
case '\\': printf("\\\\"); break;
case '\a': printf("\\a"); break;
case '\b': printf("\\b"); break;
case '\f': printf("\\f"); break;
case '\n': printf("\\n"); break;
case '\r': printf("\\r"); break;
case '\t': printf("\\t"); break;
case '\v': printf("\\v"); break;
default: if (isprint((unsigned char)c))
putchar(c);
else
printf("\\%03u",(unsigned char)c);
}
}
putchar('"');
}
static void PrintConstant(const Proto* f, int i)
{
const TValue* o=&f->k[i];
switch (ttype(o))
{
case LUA_TNIL:
printf("nil");
break;
case LUA_TBOOLEAN:
printf(bvalue(o) ? "true" : "false");
break;
case LUA_TNUMBER:
printf(LUA_NUMBER_FMT,nvalue(o));
break;
case LUA_TSTRING:
PrintString(rawtsvalue(o));
break;
default: /* cannot happen */
printf("? type=%d",ttype(o));
break;
}
}
static void PrintCode(const Proto* f)
{
const Instruction* code=f->code;
int pc,n=f->sizecode;
for (pc=0; pc<n; pc++)
{
Instruction i=code[pc];
OpCode o=GET_OPCODE(i);
int a=GETARG_A(i);
int b=GETARG_B(i);
int c=GETARG_C(i);
int bx=GETARG_Bx(i);
int sbx=GETARG_sBx(i);
int line=getline(f,pc);
printf("\t%d\t",pc+1);
if (line>0) printf("[%d]\t",line); else printf("[-]\t");
printf("%-9s\t",luaP_opnames[o]);
switch (getOpMode(o))
{
case iABC:
printf("%d",a);
if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
break;
case iABx:
if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
break;
case iAsBx:
if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
break;
}
switch (o)
{
case OP_LOADK:
printf("\t; "); PrintConstant(f,bx);
break;
case OP_GETUPVAL:
case OP_SETUPVAL:
printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
break;
case OP_GETGLOBAL:
case OP_SETGLOBAL:
printf("\t; %s",svalue(&f->k[bx]));
break;
case OP_GETTABLE:
case OP_SELF:
if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
break;
case OP_SETTABLE:
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_DIV:
case OP_POW:
case OP_EQ:
case OP_LT:
case OP_LE:
if (ISK(b) || ISK(c))
{
printf("\t; ");
if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
printf(" ");
if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
}
break;
case OP_JMP:
case OP_FORLOOP:
case OP_FORPREP:
printf("\t; to %d",sbx+pc+2);
break;
case OP_CLOSURE:
printf("\t; %p",VOID(f->p[bx]));
break;
case OP_SETLIST:
if (c==0) printf("\t; %d",(int)code[++pc]);
else printf("\t; %d",c);
break;
default:
break;
}
printf("\n");
}
}
#define SS(x) (x==1)?"":"s"
#define S(x) x,SS(x)
static void PrintHeader(const Proto* f)
{
const char* s=getstr(f->source);
if (*s=='@' || *s=='=')
s++;
else if (*s==LUA_SIGNATURE[0])
s="(bstring)";
else
s="(string)";
printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
(f->linedefined==0)?"main":"function",s,
f->linedefined,f->lastlinedefined,
S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
f->numparams,f->is_vararg?"+":"",SS(f->numparams),
S(f->maxstacksize),S(f->nups));
printf("%d local%s, %d constant%s, %d function%s\n",
S(f->sizelocvars),S(f->sizek),S(f->sizep));
}
static void PrintConstants(const Proto* f)
{
int i,n=f->sizek;
printf("constants (%d) for %p:\n",n,VOID(f));
for (i=0; i<n; i++)
{
printf("\t%d\t",i+1);
PrintConstant(f,i);
printf("\n");
}
}
static void PrintLocals(const Proto* f)
{
int i,n=f->sizelocvars;
printf("locals (%d) for %p:\n",n,VOID(f));
for (i=0; i<n; i++)
{
printf("\t%d\t%s\t%d\t%d\n",
i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
}
}
static void PrintUpvalues(const Proto* f)
{
int i,n=f->sizeupvalues;
printf("upvalues (%d) for %p:\n",n,VOID(f));
if (f->upvalues==NULL) return;
for (i=0; i<n; i++)
{
printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
}
}
void PrintFunction(const Proto* f, int full)
{
int i,n=f->sizep;
PrintHeader(f);
PrintCode(f);
if (full)
{
PrintConstants(f);
PrintLocals(f);
PrintUpvalues(f);
}
for (i=0; i<n; i++) PrintFunction(f->p[i],full);
}
*.[oa]
*.exe
*.dll
*.so
*.png
*.tmx
*.tsx
*~
rl_version.c
boot_lua.h
bounce.h
sketch008.h
smile.h
GPATH
GRTAGS
GTAGS
The zlib/libpng License
Copyright (c) 2015 Andre Leiradella
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
# retroluxury
**retroluxury** is a game library (wannabe) built on top of the [libretro](http://www.libretro.com/) API. It provides functions to blit images to the frame buffer, and to play [PCM audio](http://en.wikipedia.org/wiki/Pulse-code_modulation) and [Ogg Vorbis](http://en.wikipedia.org/wiki/Vorbis) files.
On top of that, **retroluxury** provides higher level functions to load images and wave files, and deal with sprites.
## API
The API is changing a bit, please check the header files in the `src` folder.
## Test core