# HG changeset patch # User John Tsiombikas # Date 1402386799 -10800 # Node ID 9d6368850fe15e1a6539684a374c06e88057eaa4 # Parent fd45cf0fc912ca963280fd84ae5ea8b52b1f9c7e minor enhancements and bugfixes to the console stuff diff -r fd45cf0fc912 -r 9d6368850fe1 liberebus/src/erebus.cc --- a/liberebus/src/erebus.cc Mon Jun 09 23:57:24 2014 +0300 +++ b/liberebus/src/erebus.cc Tue Jun 10 10:53:19 2014 +0300 @@ -37,6 +37,7 @@ rnd_gen.seed(time(0)); + ctx->rendering = false; ctx->scn = 0; ctx->cur_time = 0; ctx->cur_frame = 0; @@ -60,6 +61,12 @@ } } +void erb_clear(struct erebus *ctx) +{ + erb_end_frame(ctx); + ctx->scn->clear(); +} + void erb_setopti(struct erebus *ctx, enum erb_option opt, int val) { ctx->options[opt].ival = val; @@ -158,6 +165,16 @@ ctx->inv_gamma = 1.0f / erb_getoptf(ctx, ERB_OPT_GAMMA); ctx->scn->update(ctx->cur_time); + ctx->rendering = true; +} + +void erb_end_frame(struct erebus *ctx) +{ + if(ctx->tpool) { + ctx->tpool->clear_work(); + ctx->tpool->wait(); + } + ctx->rendering = false; } int erb_render(struct erebus *ctx, long timeout) @@ -169,6 +186,10 @@ int erb_render_rect(struct erebus *ctx, int x, int y, int width, int height, long timeout) { + if(!ctx->rendering) { + return 0; + } + while(ctx->tpool->pending()) { if(timeout > 0) { long wait_interval = ctx->tpool->wait(timeout); diff -r fd45cf0fc912 -r 9d6368850fe1 liberebus/src/erebus.h --- a/liberebus/src/erebus.h Mon Jun 09 23:57:24 2014 +0300 +++ b/liberebus/src/erebus.h Tue Jun 10 10:53:19 2014 +0300 @@ -28,6 +28,8 @@ struct erebus *erb_init(void); void erb_destroy(struct erebus *ctx); +void erb_clear(struct erebus *ctx); + void erb_setopti(struct erebus *ctx, enum erb_option opt, int val); void erb_setoptf(struct erebus *ctx, enum erb_option opt, float val); void erb_setoptfv(struct erebus *ctx, enum erb_option opt, float *vec); @@ -39,6 +41,8 @@ float *erb_get_framebuffer(struct erebus *ctx); void erb_begin_frame(struct erebus *ctx, long ms); +void erb_end_frame(struct erebus *ctx); + int erb_render(struct erebus *ctx, long timeout); int erb_render_rect(struct erebus *ctx, int x, int y, int width, int height, long timeout); diff -r fd45cf0fc912 -r 9d6368850fe1 liberebus/src/erebus_impl.h --- a/liberebus/src/erebus_impl.h Mon Jun 09 23:57:24 2014 +0300 +++ b/liberebus/src/erebus_impl.h Tue Jun 10 10:53:19 2014 +0300 @@ -31,6 +31,7 @@ ThreadPool *tpool; // render state + bool rendering; float inv_gamma; long cur_time; int cur_sample; diff -r fd45cf0fc912 -r 9d6368850fe1 liberebus/src/scene.cc --- a/liberebus/src/scene.cc Mon Jun 09 23:57:24 2014 +0300 +++ b/liberebus/src/scene.cc Tue Jun 10 10:53:19 2014 +0300 @@ -20,13 +20,25 @@ Scene::~Scene() { + clear(); +} + +void Scene::clear() +{ for(auto obj : objects) { delete obj; } + objects.clear(); + for(auto node : nodes) { delete node; } + nodes.clear(); + delete root; + root = 0; + + active_cam = 0; } void Scene::set_env(const Environment &env) diff -r fd45cf0fc912 -r 9d6368850fe1 liberebus/src/scene.h --- a/liberebus/src/scene.h Mon Jun 09 23:57:24 2014 +0300 +++ b/liberebus/src/scene.h Tue Jun 10 10:53:19 2014 +0300 @@ -30,6 +30,8 @@ Scene(); ~Scene(); + void clear(); + void set_env(const Environment &env); Environment &get_env(); const Environment &get_env() const; diff -r fd45cf0fc912 -r 9d6368850fe1 src/console.cc --- a/src/console.cc Mon Jun 09 23:57:24 2014 +0300 +++ b/src/console.cc Tue Jun 10 10:53:19 2014 +0300 @@ -107,7 +107,7 @@ switch(c) { case '\n': case '\r': - if(cmd_handler) { + if(!input.empty() && cmd_handler) { cmd_handler(input.c_str()); } @@ -224,6 +224,7 @@ glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); @@ -234,8 +235,8 @@ glVertex2f(0, 0); glColor4f(0.5, 0.2, 0.1, 0.7); - glVertex2f(0, -(outbox_height + line_height)); - glVertex2f(max_width, -(outbox_height + line_height)); + glVertex2f(0, -(outbox_height + line_height * 1.5)); + glVertex2f(max_width, -(outbox_height + line_height * 1.5)); glVertex2f(max_width, -outbox_height); glVertex2f(0, -outbox_height); glEnd(); @@ -257,8 +258,8 @@ float cursor_x = dtx_char_pos(inpline.c_str(), cursor + 2); glBegin(GL_QUADS); glColor4f(1, 1, 1, 0.7); - glVertex2f(cursor_x, 2); - glVertex2f(cursor_x + 2, 2); + glVertex2f(cursor_x, 0); + glVertex2f(cursor_x + 2, 0); glVertex2f(cursor_x + 2, line_height - 2); glVertex2f(cursor_x, line_height - 2); glEnd(); diff -r fd45cf0fc912 -r 9d6368850fe1 src/main.cc --- a/src/main.cc Mon Jun 09 23:57:24 2014 +0300 +++ b/src/main.cc Tue Jun 10 10:53:19 2014 +0300 @@ -574,8 +574,11 @@ static void con_parse(const char *line) { - char *buf = (char*)alloca(strlen(line) + 1); - strcpy(buf, line); + int len = strlen(line); + if(!len) return; + + char *buf = (char*)alloca(len + 1); + memcpy(buf, line, len + 1); std::vector args; char *tok; @@ -587,8 +590,29 @@ args.push_back(0); int argc = args.size() - 1; - if(strcmp(args[0], "exit") == 0) { + if(!args[0]) return; + + if(strcmp(args[0], "exit") == 0 || strcmp(args[0], "quit") == 0) { exit(0); + + } else if(strcmp(args[0], "clear") == 0) { + erb_clear(erb); + + } else if(strcmp(args[0], "stop") == 0) { + erb_end_frame(erb); + + } else if(strcmp(args[0], "render") == 0) { + long tm = 0; + if(args[1]) { + char *endp; + tm = strtol(args[1], &endp, 10); + if(endp == args[1]) { + con.printf("the argument to render must be a time value in milliseconds\n"); + return; + } + } + begin_frame(tm); + } else if(strcmp(args[0], "load") == 0) { for(int i=1; i