char *line = NULL;
size_t linesize = 0;
ssize_t linelen = 0;
+ i32 linenum = 0;
while (!hiterror && ((linelen = getline(&rawline, &linesize, file)) != -1))
{
line = rawline;
+ linenum++;
// NOTE(Brendan): Empty line
if (linelen == 1) continue;
{
settings->body_type_count = strtoll(line, &line, 10);
logprint(LOG_LEVEL_INFO, "Loaded setting: body_type_count = %ld", settings->body_type_count);
+
+ settings->body_colors.ensure_capacity(settings->body_type_count);
+ settings->body_mass_range.ensure_capacity(settings->body_type_count);
+ settings->body_relations.ensure_capacity(settings->body_type_count * settings->body_type_count);
}
else if (starts_with_and_advance("friction", &line))
{
settings->universe_scale = strtof(line, &line);
logprint(LOG_LEVEL_INFO, "Loaded setting: universe_scale = %f", settings->universe_scale);
}
+ else if (starts_with_and_advance("body_color", &line))
+ {
+ i32 body_type = strtoll(line, &line, 10);
+ f32 red = strtof(line, &line);
+ f32 green = strtof(line, &line);
+ f32 blue = strtof(line, &line);
+
+ if (body_type < 0 || body_type >= settings->body_type_count)
+ {
+ logprint(LOG_LEVEL_ERROR, "Invalid body type number: %d", body_type);
+ logprint(LOG_LEVEL_ERROR, "Expected a number between 0 and %d (inclusive)", settings->body_type_count);
+ return false;
+ }
+
+ settings->body_colors[body_type] = BodyColor { red, green, blue };
+ logprint(LOG_LEVEL_INFO, "Loaded setting: body_color[%d] = { %f, %f, %f }", body_type, red, green, blue);
+ }
+ else if (starts_with_and_advance("body_mass_range", &line))
+ {
+ i32 body_type = strtoll(line, &line, 10);
+ f32 min = strtof(line, &line);
+ f32 max = strtof(line, &line);
+
+ if (body_type < 0 || body_type >= settings->body_type_count)
+ {
+ logprint(LOG_LEVEL_ERROR, "Invalid body type number: %d", body_type);
+ logprint(LOG_LEVEL_ERROR, "Expected a number between 0 and %d (inclusive)", settings->body_type_count);
+ return false;
+ }
+
+ settings->body_mass_range[body_type] = BodyMassRange { min, max };
+ logprint(LOG_LEVEL_INFO, "Loaded setting: body_color[%d] = { %f, %f }", body_type, min, max);
+ }
+ else if (starts_with_and_advance("interaction", &line))
+ {
+ i32 body_type = strtoll(line, &line, 10);
+ i32 other_type = strtoll(line, &line, 10);
+ f32 dist = strtof(line, &line);
+ f32 force = strtof(line, &line);
+
+ if (body_type < 0 || body_type >= settings->body_type_count)
+ {
+ logprint(LOG_LEVEL_ERROR, "Invalid body type number: %d", body_type);
+ logprint(LOG_LEVEL_ERROR, "Expected a number between 0 and %d (inclusive)", settings->body_type_count);
+ return false;
+ }
+ if (other_type < 0 || other_type >= settings->body_type_count)
+ {
+ logprint(LOG_LEVEL_ERROR, "Invalid body type number: %d", body_type);
+ logprint(LOG_LEVEL_ERROR, "Expected a number between 0 and %d (inclusive)", settings->body_type_count);
+ return false;
+ }
+
+ settings->body_relations[body_type * settings->body_type_count + other_type] = BodyRelation { dist, force };
+ logprint(LOG_LEVEL_INFO, "Loaded setting: interaction[%d][%d] = { %f, %f }", body_type, other_type, dist, force);
+ }
+ else
+ {
+ logprint(LOG_LEVEL_ERROR, "Invalid syntax on line %d\n", linenum);
+ hiterror = true;
+ }
}
if (rawline) free(rawline);
- return true;
+ return !hiterror;
}
bool