[Add] Data files can be defined at runtime!
This commit is contained in:
parent
6a2f07b5b7
commit
d57941331a
@ -3,12 +3,19 @@ width = 800
|
|||||||
height = 640
|
height = 640
|
||||||
fullscreen = 0
|
fullscreen = 0
|
||||||
|
|
||||||
|
-- SCREEN.
|
||||||
|
fps = 0
|
||||||
|
|
||||||
-- JOYSTICK.
|
-- JOYSTICK.
|
||||||
-- Can be number or substring of joystick name.
|
-- Can be number or substring of joystick name.
|
||||||
joystick = "Precision"
|
joystick = "Precision"
|
||||||
|
|
||||||
-- KEYBINDINGS.
|
-- KEYBINDINGS.
|
||||||
-- Type can be keyboard, jaxis or jbutton.
|
-- 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 }
|
accel = { type = "jbutton", key = 0 }
|
||||||
left = { type = "jaxis", key = 0 }
|
left = { type = "jaxis", key = 0 }
|
||||||
right = { type = "jaxis", key = 0 }
|
right = { type = "jaxis", key = 0 }
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
function follow()
|
function follow()
|
||||||
target =1
|
target =1
|
||||||
dir = face(target)
|
dir = face(target)
|
||||||
dist = getdist(getpos(target))
|
dist = getdist(getpos(targer))
|
||||||
if dir < 10 and dist > 100 then
|
if dir < 10 and dist > 100 then
|
||||||
accel()
|
accel(dist/100-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
20
src/main.c
20
src/main.c
@ -28,6 +28,9 @@ extern const char* keybindNames[]; // Keybindings.
|
|||||||
static int quit = 0; // Primary loop.
|
static int quit = 0; // Primary loop.
|
||||||
static unsigned int time = 0; // Calculate FPS and movement.
|
static unsigned int time = 0; // Calculate FPS and movement.
|
||||||
|
|
||||||
|
#define DATA_DEF "data"
|
||||||
|
char* data = NULL;
|
||||||
|
|
||||||
static int show_fps = 1; // Default - True.
|
static int show_fps = 1; // Default - True.
|
||||||
|
|
||||||
// Prototypes.
|
// Prototypes.
|
||||||
@ -43,8 +46,8 @@ static void print_usage(char** argv) {
|
|||||||
LOG("USAGE: %s [OPTION]", argv[0]);
|
LOG("USAGE: %s [OPTION]", argv[0]);
|
||||||
LOG("Options are:");
|
LOG("Options are:");
|
||||||
LOG("\t-f, --fullscreen - Fullscreen");
|
LOG("\t-f, --fullscreen - Fullscreen");
|
||||||
//LOG("\t-w n - Set width to (n)");
|
LOG("\t-F, --fps - Toggle frames per second");
|
||||||
//LOG("\t-h n - Set height to (n)");
|
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 n, --joystick n - Use joystick (n)");
|
||||||
LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
|
LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
|
||||||
LOG("\t-h --help - Display this message and exit.");
|
LOG("\t-h --help - Display this message and exit.");
|
||||||
@ -56,6 +59,8 @@ int main(int argc, char** argv) {
|
|||||||
// Initialize SDL for possible warnings.
|
// Initialize SDL for possible warnings.
|
||||||
SDL_Init(0);
|
SDL_Init(0);
|
||||||
// Default values..
|
// Default values..
|
||||||
|
// Global.
|
||||||
|
data = DATA_DEF;
|
||||||
gl_screen.w = 800;
|
gl_screen.w = 800;
|
||||||
gl_screen.h = 640;
|
gl_screen.h = 640;
|
||||||
gl_screen.fullscreen = 0;
|
gl_screen.fullscreen = 0;
|
||||||
@ -72,6 +77,10 @@ int main(int argc, char** argv) {
|
|||||||
// Use Lua to parse configuration file.
|
// Use Lua to parse configuration file.
|
||||||
lua_State* L = luaL_newstate();
|
lua_State* L = luaL_newstate();
|
||||||
if(luaL_dofile(L, CONF_FILE) == 0) { // Conf file exists.
|
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.
|
// OpenGL properties.
|
||||||
lua_getglobal(L, "width");
|
lua_getglobal(L, "width");
|
||||||
if(lua_isnumber(L, -1))
|
if(lua_isnumber(L, -1))
|
||||||
@ -144,6 +153,7 @@ int main(int argc, char** argv) {
|
|||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "fullscreen", no_argument, 0, 'f' },
|
{ "fullscreen", no_argument, 0, 'f' },
|
||||||
{ "fps", optional_argument, 0, 'F' },
|
{ "fps", optional_argument, 0, 'F' },
|
||||||
|
{ "data", required_argument, 0, 'd' },
|
||||||
{ "joystick", required_argument, 0, 'j' },
|
{ "joystick", required_argument, 0, 'j' },
|
||||||
{ "joystick", required_argument, 0, 'J' },
|
{ "joystick", required_argument, 0, 'J' },
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
@ -152,13 +162,17 @@ int main(int argc, char** argv) {
|
|||||||
};
|
};
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 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) {
|
switch(c) {
|
||||||
case 'f':
|
case 'f':
|
||||||
gl_screen.fullscreen = 1;
|
gl_screen.fullscreen = 1;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
if(optarg != NULL) show_fps = atoi(optarg);
|
if(optarg != NULL) show_fps = atoi(optarg);
|
||||||
|
else show_fps = !show_fps;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
data = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
indjoystick = atoi(optarg);
|
indjoystick = atoi(optarg);
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
#define ABS(X) ((X<0)?-X:X)
|
#define ABS(X) ((X<0)?-X:X)
|
||||||
|
|
||||||
#define DATA "data" // Data file.
|
extern char* data; // Modifiable datafile.
|
||||||
|
#define DATA data // Data file.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user