[Add] Lua dependancy.
-- Lua parses config file.
This commit is contained in:
parent
ef46996890
commit
dd5cbe614b
12
bin/Makefile
12
bin/Makefile
@ -9,14 +9,22 @@ OBJS := $(OBJS:../src/%.c=../src/%.o)
|
|||||||
DATA = data
|
DATA = data
|
||||||
DATAFILES = $(shell find ../gfx/ ../dat/ -name '*.png' -o -name '*.xml' -print)
|
DATAFILES = $(shell find ../gfx/ ../dat/ -name '*.png' -o -name '*.xml' -print)
|
||||||
|
|
||||||
CFLAGS = -Wall `sdl-config --cflags` `xml2-config --cflags` $(VERSION)
|
CLUA = -I/usr/include/lua5.1
|
||||||
|
CSDL = `sdl-config --cflags`
|
||||||
|
CXML = `xml2-config --cflags`
|
||||||
|
CGL =
|
||||||
|
CFLAGS = -Wall $(CLUA) $(CSDL) $(CXML) $(CGL) $(VERSION)
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CFLAGS += -g3 -DDEBUG
|
CFLAGS += -g3 -DDEBUG
|
||||||
else
|
else
|
||||||
CFLAGS += -O2
|
CFLAGS += -O2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDFLAGS = -lm `sdl-config --libs` `xml2-config --libs` -lSDL_image -lGL
|
LDLUA = -llua5.1
|
||||||
|
LDSDL = `sdl-config --libs` -lSDL_image
|
||||||
|
LDXML = `xml2-config --libs`
|
||||||
|
LDGL = -lGL
|
||||||
|
LDFLAGS = -lm $(LDLUA) $(LDSDL) $(LDXML) $(LDGL)
|
||||||
|
|
||||||
%.o: ../src/%.c
|
%.o: ../src/%.c
|
||||||
@gcc -c $(CFLAGS) -o $@ $<
|
@gcc -c $(CFLAGS) -o $@ $<
|
||||||
|
34
src/main.c
34
src/main.c
@ -1,4 +1,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
#include <lualib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -14,12 +17,16 @@
|
|||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
|
|
||||||
|
#define CONF_FILE "conf"
|
||||||
|
|
||||||
static int quit = 0;
|
static int quit = 0;
|
||||||
|
|
||||||
static unsigned int time = 0;
|
static unsigned int time = 0;
|
||||||
|
|
||||||
// Prototypes.
|
// Prototypes.
|
||||||
|
|
||||||
|
void print_usage(char** argv);
|
||||||
|
|
||||||
// Update.
|
// Update.
|
||||||
static void update_all(void);
|
static void update_all(void);
|
||||||
|
|
||||||
@ -37,8 +44,6 @@ void print_usage(char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
SDL_Event event;
|
|
||||||
|
|
||||||
// Default values..
|
// Default values..
|
||||||
gl_screen.w = 800;
|
gl_screen.w = 800;
|
||||||
gl_screen.h = 640;
|
gl_screen.h = 640;
|
||||||
@ -47,6 +52,30 @@ int main(int argc, char** argv) {
|
|||||||
int indjoystick = -1;
|
int indjoystick = -1;
|
||||||
char* namjoystick = NULL;
|
char* namjoystick = NULL;
|
||||||
|
|
||||||
|
// Use Lua to parse configuration file.
|
||||||
|
lua_State* L = luaL_newstate();
|
||||||
|
if(luaL_dofile(L, CONF_FILE) == 0) {
|
||||||
|
// OpenGL.
|
||||||
|
lua_getglobal(L, "width");
|
||||||
|
if(lua_isnumber(L, -1))
|
||||||
|
gl_screen.w = (int)lua_tonumber(L, -1);
|
||||||
|
lua_getglobal(L, "height");
|
||||||
|
if(lua_isnumber(L, -1))
|
||||||
|
gl_screen.h = (int)lua_tonumber(L, -1);
|
||||||
|
lua_getglobal(L, "fullscreen");
|
||||||
|
if(lua_isnumber(L, -1))
|
||||||
|
if((int)lua_tonumber(L, -1) == 1)
|
||||||
|
gl_screen.fullscreen = 1;
|
||||||
|
|
||||||
|
// Joystick.
|
||||||
|
lua_getglobal(L, "joystick");
|
||||||
|
if(lua_isnumber(L, -1))
|
||||||
|
indjoystick = (int)lua_tonumber(L, -1);
|
||||||
|
else if(lua_isstring(L, -1))
|
||||||
|
namjoystick = strdup((char*)lua_tostring(L, -1));
|
||||||
|
}
|
||||||
|
lua_close(L);
|
||||||
|
|
||||||
// Parse arguments.
|
// Parse arguments.
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while((c = getopt(argc, argv, "fJ:j:hv")) != -1) {
|
while((c = getopt(argc, argv, "fJ:j:hv")) != -1) {
|
||||||
@ -104,6 +133,7 @@ int main(int argc, char** argv) {
|
|||||||
time = SDL_GetTicks();
|
time = SDL_GetTicks();
|
||||||
|
|
||||||
// Main looops.
|
// Main looops.
|
||||||
|
SDL_Event event;
|
||||||
while(!quit) {
|
while(!quit) {
|
||||||
// Event loop.
|
// Event loop.
|
||||||
while(SDL_PollEvent(&event)) {
|
while(SDL_PollEvent(&event)) {
|
||||||
|
10
src/opengl.c
10
src/opengl.c
@ -272,6 +272,7 @@ int gl_init(void) {
|
|||||||
//SDL_ShowCursor(SDL_DISABLE);
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
// Get available fullscreen modes.
|
// Get available fullscreen modes.
|
||||||
|
if(gl_screen.fullscreen) {
|
||||||
modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
|
modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
|
||||||
if(modes == NULL) {
|
if(modes == NULL) {
|
||||||
WARN("No fullscreen modes available");
|
WARN("No fullscreen modes available");
|
||||||
@ -281,22 +282,23 @@ int gl_init(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(modes == (SDL_Rect**)-1)
|
else if(modes == (SDL_Rect**)-1)
|
||||||
DEBUG("All fullscreen modes available.");
|
DEBUG("All fullscreen modes available");
|
||||||
else {
|
else {
|
||||||
DEBUG("Available fullscreen modes:");
|
DEBUG("Available fullscreen modes:");
|
||||||
for(i = 0; modes[i]; ++i) {
|
for(i = 0; modes[i]; ++i) {
|
||||||
DEBUG("\t\t%d x %d", modes[i]->w, modes[i]->h);
|
DEBUG("\t%dx%d", modes[i]->w, modes[i]->h);
|
||||||
if(flags & SDL_FULLSCREEN && modes[i]->w == gl_screen.w && modes[i]->h == gl_screen.h)
|
if(flags & SDL_FULLSCREEN && modes[i]->w == gl_screen.w && modes[i]->h == gl_screen.h)
|
||||||
supported = 1;
|
supported = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make sure fullscreen mode is supported.
|
// Make sure fullscreen mode is supported.
|
||||||
if((flags & SDL_FULLSCREEN) && (!supported)) {
|
if(flags & SDL_FULLSCREEN && !supported) {
|
||||||
WARN("Fullscreen mode %d x %d is not supported by your current setup, switching to another mode.",
|
WARN("Fullscreen mode %dx%d is not supported by your current setup, switching to another mode",
|
||||||
gl_screen.w, gl_screen.h);
|
gl_screen.w, gl_screen.h);
|
||||||
gl_screen.w = modes[0]->w;
|
gl_screen.w = modes[0]->w;
|
||||||
gl_screen.h = modes[0]->h;
|
gl_screen.h = modes[0]->h;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test the setup.
|
// Test the setup.
|
||||||
depth = SDL_VideoModeOK(gl_screen.w, gl_screen.h, gl_screen.depth, flags);
|
depth = SDL_VideoModeOK(gl_screen.w, gl_screen.h, gl_screen.depth, flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user