[Add] Data files can be defined at runtime!

This commit is contained in:
Allanis 2013-02-04 13:26:23 +00:00
parent 6a2f07b5b7
commit d57941331a
4 changed files with 35 additions and 13 deletions

View File

@ -3,12 +3,19 @@ width = 800
height = 640
fullscreen = 0
-- SCREEN.
fps = 0
-- JOYSTICK.
-- Can be number or substring of joystick name.
joystick = "Precision"
-- KEYBINDINGS.
-- Type can be keyboard, jaxis or jbutton.
--
-- If left is an axis, it will automatically set right to the same axis.
-- setting both to the same axis (key).
-- You can use reverse = 1 option to reverse them.
accel = { type = "jbutton", key = 0 }
left = { type = "jaxis", key = 0 }
right = { type = "jaxis", key = 0 }

View File

@ -1,9 +1,9 @@
function follow()
target = 1
target =1
dir = face(target)
dist = getdist(getpos(target))
dist = getdist(getpos(targer))
if dir < 10 and dist > 100 then
accel()
accel(dist/100-1)
end
end

View File

@ -28,6 +28,9 @@ extern const char* keybindNames[]; // Keybindings.
static int quit = 0; // Primary loop.
static unsigned int time = 0; // Calculate FPS and movement.
#define DATA_DEF "data"
char* data = NULL;
static int show_fps = 1; // Default - True.
// Prototypes.
@ -43,8 +46,8 @@ static void print_usage(char** argv) {
LOG("USAGE: %s [OPTION]", argv[0]);
LOG("Options are:");
LOG("\t-f, --fullscreen - Fullscreen");
//LOG("\t-w n - Set width to (n)");
//LOG("\t-h n - Set height to (n)");
LOG("\t-F, --fps - Toggle frames per second");
LOG("\t-d s, --data s - Set the data file to be s");
LOG("\t-j n, --joystick n - Use joystick (n)");
LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
LOG("\t-h --help - Display this message and exit.");
@ -56,6 +59,8 @@ int main(int argc, char** argv) {
// Initialize SDL for possible warnings.
SDL_Init(0);
// Default values..
// Global.
data = DATA_DEF;
gl_screen.w = 800;
gl_screen.h = 640;
gl_screen.fullscreen = 0;
@ -72,6 +77,10 @@ int main(int argc, char** argv) {
// Use Lua to parse configuration file.
lua_State* L = luaL_newstate();
if(luaL_dofile(L, CONF_FILE) == 0) { // Conf file exists.
// Global.
lua_getglobal(L, "data");
if(lua_isstring(L, -1))
data = strdup((char*)lua_tostring(L, -1));
// OpenGL properties.
lua_getglobal(L, "width");
if(lua_isnumber(L, -1))
@ -142,23 +151,28 @@ int main(int argc, char** argv) {
// Parse arguments.
static struct option long_options[] = {
{ "fullscreen", no_argument, 0, 'f' },
{ "fps", optional_argument, 0, 'F' },
{ "joystick", required_argument, 0, 'j' },
{ "joystick", required_argument, 0, 'J' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "fullscreen", no_argument, 0, 'f' },
{ "fps", optional_argument, 0, 'F' },
{ "data", required_argument, 0, 'd' },
{ "joystick", required_argument, 0, 'j' },
{ "joystick", required_argument, 0, 'J' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
int option_index = 0;
int c = 0;
while((c = getopt_long(argc, argv, "fFJ:j:hv", long_options, &option_index)) != -1) {
while((c = getopt_long(argc, argv, "fFd:J:j:hv", long_options, &option_index)) != -1) {
switch(c) {
case 'f':
gl_screen.fullscreen = 1;
break;
case 'F':
if(optarg != NULL) show_fps = atoi(optarg);
else show_fps = !show_fps;
break;
case 'd':
data = strdup(optarg);
break;
case 'j':
indjoystick = atoi(optarg);

View File

@ -5,5 +5,6 @@
#define ABS(X) ((X<0)?-X:X)
#define DATA "data" // Data file.
extern char* data; // Modifiable datafile.
#define DATA data // Data file.