writing scene
This commit is contained in:
parent
0be3768867
commit
fe34c61b12
3 changed files with 17 additions and 8 deletions
|
|
@ -19,22 +19,19 @@
|
|||
#include "kubo_command.h"
|
||||
|
||||
static inline void kubo_command_exit(struct kubo_context *context);
|
||||
static inline void kubo_command_write(struct kubo_context *context);
|
||||
|
||||
static const struct kubo_command_data kubo_commands[] = {
|
||||
{":q", kubo_command_exit}};
|
||||
{":q", kubo_command_exit}, {":w", kubo_command_write}};
|
||||
|
||||
static const size_t kubo_commands_size =
|
||||
sizeof(kubo_commands) / sizeof(kubo_commands[0]);
|
||||
|
||||
static struct kubo_char_arr command;
|
||||
|
||||
void kubo_command_init() {
|
||||
kubo_char_arr_init(&command);
|
||||
}
|
||||
void kubo_command_init() { kubo_char_arr_init(&command); }
|
||||
|
||||
void kubo_command_cleanup() {
|
||||
kubo_char_arr_free(&command);
|
||||
}
|
||||
void kubo_command_cleanup() { kubo_char_arr_free(&command); }
|
||||
|
||||
void kubo_command_append_char(int c) { kubo_char_arr_add(&command, c); }
|
||||
|
||||
|
|
@ -61,3 +58,7 @@ void kubo_command_clear() { kubo_char_arr_clear(&command); }
|
|||
static inline void kubo_command_exit(struct kubo_context *context) {
|
||||
context->exit_pending = true;
|
||||
}
|
||||
|
||||
static inline void kubo_command_write(struct kubo_context *context) {
|
||||
kubo_file_write(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "kubo_char_arr.h"
|
||||
#include "kubo_context.h"
|
||||
#include "kubo_file.h"
|
||||
|
||||
typedef void (*kubo_command_function)(struct kubo_context *context);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,10 +47,11 @@ void kubo_file_write(struct kubo_context *context) {
|
|||
|
||||
struct kubo_file_scene *scene = malloc(sizeof(struct kubo_file_scene));
|
||||
scene->walls_count = context->walls.count;
|
||||
scene->walls = malloc(sizeof(struct kubo_file_wall) * scene->walls_count);
|
||||
scene->walls = malloc(sizeof(struct kubo_file_wall) * context->walls.count);
|
||||
|
||||
for (size_t i = 0; i < scene->walls_count; i++) {
|
||||
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
||||
scene->walls[i].vertices_count = wall->vertices.count;
|
||||
scene->walls[i].vertices =
|
||||
malloc(sizeof(kubo_file_vertex) * wall->vertices.count);
|
||||
for (size_t j = 0; j < wall->vertices.count; j++) {
|
||||
|
|
@ -66,4 +67,10 @@ void kubo_file_write(struct kubo_context *context) {
|
|||
if (err != CYAML_OK) {
|
||||
printf("Error writing yaml file %s\n", context->file_name);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < scene->walls_count; i++) {
|
||||
free(scene->walls[i].vertices);
|
||||
}
|
||||
|
||||
free(scene);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue