Author Topic: How to autoload game after video  (Read 819 times)

SaturnTeam

  • Jr. Member
  • **
  • Posts: 69
  • Karma: +5/-0
    • View Profile
    • Saturn Team
Re: How to autoload game after video
« Reply #15 on: July 16, 2018, 03:19:26 am »
Okay. That's good feedback. I appreciate it. I'm still learning C, so it's a bit difficult. I had tried setting the global malloc in the makefile, and it always returned the problem of too much memory being eaten up. I'll work on lowering the background memory use. I see what you're saying about loading the video once. I couldn't figure out why it was only loaded in jo_main in the demo. So that makes sense.
Founder of Saturn Team

ponut64

  • Full Member
  • ***
  • Posts: 181
  • Karma: +13/-0
    • View Profile
Re: How to autoload game after video
« Reply #16 on: July 16, 2018, 03:23:26 am »
I'm glad I can help, hopefully I did. Also, I've pushed a million edits to the post.

logi

  • Newbie
  • *
  • Posts: 4
  • Karma: +1/-0
    • View Profile
Re: How to autoload game after video
« Reply #17 on: July 16, 2018, 06:38:46 pm »
I have not really spent much time on this issue, but I have noticed one thing.

If I let the video play through and wait for the my_video_stopped() callback to be executed before I try to load the background image, then the out of memory error is thrown.

But if I manually stop the video using the jo_video_stop() function just 1 frame before the video ends and remove the callback, I am then able to load the background image into memory.
Although the video window is still being displayed over the background image it is not giving any memory errors.

https://youtu.be/LYE-Hb-WM8k

Code: [Select]
#include <jo/jo.h>
#include <jo/video.h>

int viedo_draw_id;
int video_counter;

void my_draw(void) {
video_counter += 1;

if (video_counter < 385) {
// Yes, it consume a lot of memory during playing :)
jo_printf(0, 0, "Dynamic memory usage: %d%%  ", jo_memory_usage_percent());
jo_printf(0, 1, "Sprite memory usage: %d%%  ", jo_sprite_usage_percent());
jo_printf(0, 5, jo_get_last_error());
jo_sprite_draw3D(jo_get_video_sprite(), 0, 0, 170);
}
else {
jo_core_remove_callback(viedo_draw_id);
jo_sprite_free_from(jo_get_video_sprite());
jo_video_stop();
my_background();
}
}

void my_background() {
jo_clear_screen();
        jo_img      bg;
        bg.data = NULL;
        jo_tga_loader(&bg, "BG", "BG.TGA", JO_COLOR_Transparent);
        jo_set_background_sprite(&bg, 0, 0);
        jo_free_img(&bg);
}

void  my_video_stopped(void) {

}

void jo_main(void) {
jo_core_init(JO_COLOR_Black);
video_counter = 0;

if (jo_video_open_file("SAMPLE.CPK"))
            jo_video_play(my_video_stopped);

viedo_draw_id = jo_core_add_callback(my_draw);
jo_core_run();
}

EDIT:
I also modified the 'RING_BUF_SIZ' in the video.c file, which is why the video is now consuming less dynamic memory.
« Last Edit: July 16, 2018, 06:41:55 pm by logi »

 

Sitemap 1 2 3 4 5 6 7 8 9 10 
SMF spam blocked by CleanTalk