Sega Saturn Development > General Jo Engine Help

Best way to: Put an image background

(1/2) > >>

KeiDash:
Hi everyone.

In order not to create new entries, I take advantage of this same space to ask the question.

See the question here please



I'm doing some test on JoEngine. I've started with printing some text on screen with jo_printf function based on gamepad keys pressed and would like to know the best way to do this, I'm explain it.

I've two functions, function A and function B. Each one, has a validation that if the key A was pressed, continue doing something. The A method call to B method when A key was pressed.


--- Code: ---
void A()
{
   do
   {
      //do something here
   } while(!jo_is_pad1_key_pressed(JO_KEY_A))

   B();
}

void B()
{
   do
   {
      //do something here too
   } while(!jo_is_pad1_key_pressed(JO_KEY_A))
}

--- End code ---

In this case, if in A function the A button was pressed, then call at B function.

The problem? The call from A to B it's so fast that the B function ends because it detected that the A button was pressed. It's something like the A buttom continued pressed in both cases or the time elapsed was very short that function B detected that A buttom was pressed to.

Exists some method or technique that wait between one call to other?


In other side, I've errors continuously making the compilation, but the output doesn't say something like Error in file.c X line X.. throw messages like:


--- Code: ---
sh-coff-gcc.exe: main.o: No such file or directory

--- End code ---

I'm making the compilation on Windows Command Line and in the Windows Power Shell. I solved it deleting the *.o files and compiling again, but I don't understand where is the problem.

Thanks at all.

Regards,

ponut64:
1. Use compile.bat and edit compile.bat to ensure it ends with PAUSE. At which point you don't need any command line, just double-click it and it will halt so you can read what happened.
If you're still missing main.o, check the makefile in the project directory. it must list your source files in the SRCS line.

2.

Both function A and B halts the program if you never press A. THE ENTIRE PROGRAM.

Instead:


--- Code: ---
void stuff_for_A(void){

static bool lastTouch = false;

 if(jo_is_pad1_key_pressed(JO_KEY_A)){
 jo_printf(lineX, lineY, "stuff%i", data);
 lastTouch = true;
 } else if(lastTouch == true){
 jo_printf(lineX, lineY, "                                         ");
 lastTouch = false;
}

}

--- End code ---
What does this do:
When you press the A button, print text.
When you release the A button, on the next frame, clears that text area off the screen.

If you want to insert a wait, add a timer. Don't try and halt by process, that slows down the entire program.
And of course, I'm not talking about some abstraction of a timer. You make an integer and add to it every frame. When it reaches the number you want, run the associated function and set it back to zero.

KeiDash:

--- Quote from: ponut64 on June 25, 2019, 12:47:11 am ---1. Use compile.bat and edit compile.bat to ensure it ends with PAUSE. At which point you don't need any command line, just double-click it and it will halt so you can read what happened.
If you're still missing main.o, check the makefile in the project directory. it must list your source files in the SRCS line.

2.

Both function A and B halts the program if you never press A. THE ENTIRE PROGRAM.

Instead:


--- Code: ---
void stuff_for_A(void){

static bool lastTouch = false;

 if(jo_is_pad1_key_pressed(JO_KEY_A)){
 jo_printf(lineX, lineY, "stuff%i", data);
 lastTouch = true;
 } else if(lastTouch == true){
 jo_printf(lineX, lineY, "                                         ");
 lastTouch = false;
}

}

--- End code ---
What does this do:
When you press the A button, print text.
When you release the A button, on the next frame, clears that text area off the screen.

If you want to insert a wait, add a timer. Don't try and halt by process, that slows down the entire program.
And of course, I'm not talking about some abstraction of a timer. You make an integer and add to it every frame. When it reaches the number you want, run the associated function and set it back to zero.

--- End quote ---

Thanks for your reply.

As I see, I'm not on the wrong track. I'm doing something similar to what you explain, with a variable that "prevent" the next action, but, I wans't using a static var. As you say, it's better in this case.

I thought that this "practice" maybe no was the best way to do that.

For the compilation issue, I've checked my makefile and it's right. It has all files that I need in the SRCS line, included main.c. The curious case is that I included a new line in compile.bat. I wrote DEL *.o as second line before throw the compilation and now works always right.

I don't know if this happening only at me or exists more users that has the same issue.

KeiDash:
I use the same message to avoid creating another post.

I'm looking the Samples in the JoEngine to improve my knowledge. I'm trying to put 2 different background images in "2 screens" (one method call other and each one has it own bg).

I'm using the jo_tga_loader function like this:

--- Code: ---
   //SCREEN 1
   imgBackground.data = JO_NULL;
   jo_tga_loader(&imgBackground, "BG", "IMG1.TGA", JO_COLOR_Transparent);
   jo_set_background_sprite(&imgBackground, 0, 0);
   jo_free_img(&imgBackground);

   //SCREEN 2
   imgBackground.data = JO_NULL;
   jo_tga_loader(&imgBackground, "BG", "IMG2.TGA", JO_COLOR_Transparent);
   jo_set_background_sprite(&imgBackground, 0, 0);
   jo_free_img(&imgBackground);

--- End code ---

The first screen (the menu) load the IMG1.TGA file. When the A button it's pressed, clear the screen and the background and then loads the IMG2.TGA.

If in the screen 2, the B button it's pressed, clear the screen and the background too and come back to the screen 1 and loads again the IMG1.TGA file.

Up to this point there are no problems. The problem comes now, if I repeat the process. If I press the A button again to change SCREEN 1 to 2, the engine throws an error saying that the file "IM___.TGA" file not found.



1. In the error, the file name not is complete, the complete file name is "IMG2.TGA", whats happening here?
2. To view a possible function anotations, I went to read the documentation of jo_tga_loader, but this method doesn't exists on the original documentation, instead exists the function jo_tga_loader_from_stream

What's going on?
This is the best way to load an image background?
It's a bad idea load a TGA file in the background (for the performance)?
If jo_tga_loader_from_stream is the only one method, how I can convert the image background to binary to use this method?
Exists any other option?

Thanks all.

PD: I'm using Yabause or mednafen to do it, but each emulator works different.

ponut64:
It's possible that one or another of jo engine's memory pointers are going out of range when you repeat this much.

It may not be in the documentation, but it is definitely in the source code.

Upon review, every call of jo_tga_loader will malloc.
It is true that jo_free_img is supposed to clear this. But, it is important you ensure that this function never repeats on a pointer unless that pointer is allocated.

There's also the issue of runtime performance.
The file system expects a system halt. You could try putting a while loop on tga loader and jo_free calls. This isn't for a logical reason, instead it is for the reason that the SH2 will cache instructions up to a conditional jump, could be causing problems.

Another thing is that upon review, jo_tga_loader should work fine loading different files (as long as the first file is the maximum image size you'll use) to the same image data region without being free'd. img->data is never treated with an incremental pointer; none is stored except in for loops. jo_free_img destroys the pointer and points img->data to NULL. That can cause errors if it's ever used out of order.

Why would it ever be used out of order?
VDP2 and Slave SH2 don't halt where Master SH2 halts.
Also, potentially compiler errors.

I've also had success clearing up file system errors by disassociating file names. IMG1 and IMG2 could be too similar and subtle memory corruptions that "just happen" with Jo engine make the code confused. It's possible that IM  .TGA is expressing that the text "G1" and/or "G2" were corrupted into illegal text codes. I suggest you specify "IMD1" and "IBG2" or something like that.

I will say that whatever Yabause is doing, ignore it. It's most likely wrong.
Trust Mednafen.

Navigation

[0] Message Index

[#] Next page

Sitemap 1 2 3 4 5 6 7 8 9 10 
Go to full version