[dependencies]
git://onyxlang.io/repo/openal=0.0.2
-git://onyxlang.io/repo/ogre=0.0.8
+git://onyxlang.io/repo/ogre=0.0.10
[dependency_folders]
git://onyxlang.io/repo/openal=openal
entity.flags |= .Interactable;
if entity->has(InteractableComponent) {
- debug_log(.Error, "DispenserComponent expected entity to not have an InteractableComponent");
+ log(.Error, "DispenserComponent expected entity to not have an InteractableComponent");
}
scene->modify_component(entity, InteractableComponent) {
item := scene->create_from_schematic("Item_Entity");
if item == null {
- debug_log(.Error, "Bad schematic type.");
+ log(.Error, "Bad schematic type.");
return;
}
array.free(^path);
collision_mask := scene->first_component(CollisionMaskComponent);
if !(collision_mask->get_path(entity.pos, target_location, ^path)) {
- debug_log(.Warning, "No path for patron.");
+ log(.Warning, "No path for patron.");
return;
}
err, input_file := os.open(path, .Read);
if err != .None {
- debug_log(.Error, "Failed to open file: {}", path);
+ logf(.Error, "Failed to open file: {}", path);
return;
}
defer os.close(^input_file);
|> string.strip_whitespace();
if items->has(item_id) {
- debug_log(.Warning, "Duplicate definition for item with id '{}', on line: {}.", item_id);
+ logf(.Warning, "Duplicate definition for item with id '{}', on line: {}.", item_id);
}
item_id = string.alloc_copy(item_id, allocator=item_allocator);
member := any_nested_selector(as_any(current_item), var_name);
if member.data == null {
- debug_log(.Warning, "'{}' is not a valid member of Item on line {}.", var_name, line_number);
+ logf(.Warning, "'{}' is not a valid member of Item on line {}.", var_name, line_number);
continue;
}
if !conv.parse_any(member.data, member.type, line) {
- debug_log(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number);
+ logf(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number);
continue;
}
}
s_info := cast(^Type_Info_Struct) it;
if struct_inherits(~~ index, Component) {
- debug_log(.Debug, "Discovered component: '{}'", s_info.name);
+ logf(.Debug, "Discovered component: '{}'", s_info.name);
comp_type := cast(type_expr) index;
if !(component_vtables->has(comp_type)) {
schematic.create = *cast(^(^Scene) -> ^Entity) ^it.func;
schematics[schematic.name] = schematic;
- debug_log(.Debug, "Discovered schematic: '{}'", schematic.name);
+ logf(.Debug, "Discovered schematic: '{}'", schematic.name);
}
}
case #default {
msg := conv.format(output_buffer, "Unhandled output case: {}\n", it.type);
- debug_log(.Error, msg);
+ logf(.Error, msg);
}
}
}
scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) {
err, input_file := os.open(filename, .Read);
if err != .None {
- debug_log(.Error, "Failed to open file: {}", filename);
+ logf(.Error, "Failed to open file: {}", filename);
return;
}
defer os.close(^input_file);
entity_kind := string.advance(line)
|> (x => str.{x.data, x.count - 1})(); // In the grossest way possible remove one character from the end.
- debug_log(.Debug, "Creating entity from schematic: {}.", entity_kind);
+ logf(.Debug, "Creating entity from schematic: {}.", entity_kind);
if entity_kind == "Custom" {
current_entity = this->make();
} else {
current_entity = this->create_from_schematic(entity_kind);
if current_entity == null {
- debug_log(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number);
+ logf(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number);
current_entity = null;
continue;
}
if line[0] == #char ":" {
if current_entity == null {
- debug_log(.Error, "Attempt to create a component when no entity is specified on line {}.", line_number);
+ logf(.Error, "Attempt to create a component when no entity is specified on line {}.", line_number);
continue;
}
} else {
current_component = scene->create_component(component_type);
- debug_log(.Debug, "Adding {} to entity.", component_type);
+ logf(.Debug, "Adding {} to entity.", component_type);
current_entity->add(current_component);
}
member := any_nested_selector(any.{ptr, type}, var_name);
if member.data == null {
t_info := cast(^Type_Info_Struct) get_type_info(type);
- debug_log(.Warning, "'{}' is not a valid member of '{}' on line {}.", var_name, t_info.name, line_number);
+ logf(.Warning, "'{}' is not a valid member of '{}' on line {}.", var_name, t_info.name, line_number);
continue;
}
if !conv.parse_any(member.data, member.type, line) {
- debug_log(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number);
+ logf(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number);
continue;
}
}
Audio_Manager.tick();
if is_key_just_up(GLFW_KEY_F8) {
- debug_log(.Info, "Saving to '{}'.", quick_save_file);
+ log(.Info, "Saving to '{}'.", quick_save_file);
scene->save_to_file(quick_save_file);
}
if is_key_just_up(GLFW_KEY_F9) {
- debug_log(.Info, "Loading from '{}'.", quick_save_file);
+ log(.Info, "Loading from '{}'.", quick_save_file);
scene->load_from_file(quick_save_file);
}
init :: () {
if !ogre_init() {
- debug_log(.Critical, "Failed to initialize OGRE!");
+ log(.Critical, "Failed to initialize OGRE!");
os.exit(1);
}
main :: () {
random.set_seed(os.time());
- debug_set_level(.Info);
+ default_log_level(.Info);
+
init();
run();
deinit();
alcMakeContextCurrent(audio_context);
if alGetError() != AL_NO_ERROR {
- debug_log(.Critical, "Error creating audio context!!");
+ log(.Critical, "Error creating audio context!!");
}
}
buffer: u32;
alGenBuffers(1, ^buffer);
if alGetError() != AL_NO_ERROR {
- debug_log(.Error, "Error creating audio buffer!");
+ log(.Error, "Error creating audio buffer!");
return .{0};
}
*out_texture = texture;
} else {
- debug_log(.Error, "Failed to load texture '{}' for asset queued here: {}:{},{}.\n", path, location.file, location.line, location.column);
+ logf(.Error, "Failed to load texture '{}' for asset queued here: {}:{},{}.\n", path, location.file, location.line, location.column);
}
} else {
- debug_log(.Error, "Texture path not found for texture asset load here: {}:{},{}.\n", location.file, location.line, location.column);
+ logf(.Error, "Texture path not found for texture asset load here: {}:{},{}.\n", location.file, location.line, location.column);
}
}
case #default {
- debug_log(.Warning, "Asset loader does not know how to load a '{}'.\n", type);
+ logf(.Warning, "Asset loader does not know how to load a '{}'.\n", type);
}
}
}
//
// This may become an in-game or external file logger in the future,
// but for now this is just for logging to the command line.
+//
-use package core
-
-Enable_Log_Colors :: false
-
-Log_Level :: enum {
- Debug;
- Info;
- Warning;
- Error;
- Critical;
-}
-
-debug_set_level :: (level: Log_Level) {
- log_level = level;
-}
-
-debug_log :: (level: Log_Level, format: str, args: ..any) {
- debug_log_va(level, format, ~~args);
-}
-
-debug_log_va :: (level: Log_Level, format: str, args: [] any) {
- if level < log_level do return;
-
+logf :: (level: Log_Level, format: str, args: ..any) {
buf: [2048] u8;
- output := conv.format_va(buf, format, args);
- #if Enable_Log_Colors {
- color_spec: str;
- switch level {
- case .Critical do color_spec = "1;91";
- case .Error do color_spec = "1;31";
- case .Warning do color_spec = "1;33";
- case .Info do color_spec = "94";
- }
-
- printf("\x1b[{}m[{w5}] {}\x1b[0m\n", color_spec, level_string(level), output);
- } else {
- printf("[{w5}] {}\n", level_string(level), output);
- }
+ log(level, core.conv.format_va(buf, format, args));
}
-
-#local level_string :: (level: Log_Level) => {
- switch level {
- case .Debug do return "DEBUG";
- case .Info do return "INFO";
- case .Warning do return "WARN";
- case .Error do return "ERROR";
- case .Critical do return "CRIT";
- }
-
- return "";
-}
-
-#local log_level := Log_Level.Debug;
\ No newline at end of file