Add glib, control structures

This commit is contained in:
Stefan Bühler 2008-07-11 23:30:34 +02:00
parent fd3652089f
commit b955e4ea9d
3 changed files with 125 additions and 1 deletions

View File

@ -1,6 +1,73 @@
#ifndef _CONTROL_H
#define _CONTROL_H
#include <glib.h>
typedef enum { ACCELERATING, ROLLING, BRAKING } accel_t;
typedef enum { TURN_HARD_LEFT, TURN_LEFT, TURN_STRAIGT, TURN_RIGHT, TURN_HARD_RIGHT } turn_t;
typedef enum { BOLDER, CRATER, MARTIAN } object_t;
struct object;
typedef struct object object;
struct vehicle;
typedef struct vehicle vehicle;
struct telemetry;
typedef struct telemetry telemetry;
struct map;
typedef struct map map;
struct trial;
typedef struct trial trial;
typedef unsigned int timestamp;
struct object {
object_t type;
double x, y, rad;
double dir, speed;
};
struct vehicle {
accel_t accel;
turn_t turn;
double x, y;
double dir, speed;
};
struct telemetry {
timestamp ts;
vehicle vehicle;
GArray objects;
};
struct map {
float dx, dy;
timestamp limit;
float min_sensor, max_sensor;
float max_speed, max_turn, max_turn_hard;
GList solid_objects;
};
struct trial {
map map;
timestamp last_ts;
GList telemetry_data;
vehicle vehicle; /* our view */
};
/* trial */
trial *trial_new();
void trial_reset_run(trial *trial);
void trial_wait_for_start(trial *trial);
void trial_check_input(trial *trial);
void trial_wait_for_input(trial *trial);
void trial_free(trial *trial);
#endif

View File

@ -13,4 +13,4 @@ def build(bld):
main.name = 'icfp08'
main.source = main_source
main.target = 'icfp08'
main.uselib += ''
main.uselib += 'glib'

57
wscript
View File

@ -9,6 +9,57 @@ APPNAME='icfp08'
srcdir = '.'
blddir = 'build'
###########################
import types
def tolist(x):
if type(x) is types.ListType:
return x
return [x]
def env_mod(conf, use):
types = [ 'LIB', 'STATICLIB', 'LIBPATH', 'CPPPATH', 'CXXDEFINES', 'CCFLAGS', 'CXXFLAGS', 'LINKFLAGS' ]
bak = {}
for t in types:
bak[t] = conf.env[t]
for u in use:
conf.env[t] = tolist(conf.env[t]) + tolist(conf.env['%s_%s' % (t, u)])
return bak
def env_mod_revert(conf, bak):
for (k,v) in bak.items():
conf.env[k] = v
def CHECK_INCLUDE_FILES(conf, header, define, uselib = '', path = None, mandatory = 0, use = []):
envbak = env_mod(conf, use)
hconf = conf.create_header_configurator()
hconf.mandatory = mandatory
hconf.name = header
hconf.uselib_store = uselib
hconf.define = define
if path: hconf.path += path
res = hconf.run()
env_mod_revert(conf, envbak)
return res
def PKGCONFIG(conf, name, uselib = None, define = '', version = '', mandatory = 0):
if not uselib: uselib = name
hconf = conf.create_pkgconfig_configurator()
hconf.name = name
hconf.version = version
hconf.uselib_store = uselib
hconf.define = define
hconf.mandatory = mandatory
res = hconf.run()
return res
###########################
def set_options(opt):
opt.tool_options('compiler_cc')
opt.tool_options('ragel', tdir = '.')
@ -22,6 +73,12 @@ def configure(conf):
# '-fPIC', '-D_GNU_SOURCE',
]
conf.env['CCFLAGS'] += common_ccflags
PKGCONFIG(conf, "glib-2.0", uselib = 'glib', mandatory = 1)
incdir = conf.env['CPPPATH_glib'][0]
conf.env['CPPPATH_glib'] += [ incdir+'/glib-2.0/', incdir + '/glib-2.0/include/' ]
CHECK_INCLUDE_FILES(conf, "glib.h", "HAVE_GLIB_H", uselib = 'glib', use = ['glib'], mandatory = 1)
def build(bld):
bld.add_subdirs('src')