Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Chapter 04] Unclear where to put the FileHandler code

So I just finished the part about displaying the single picture ("lenna.png") in chapter 04. There's one part that seemed unclear to me and that's where to put this FileHandler code:

int Width, Height;
char* OurRawData = FileHandler.Load((char*)"../assets/lenna.png", &Width, &Height);
if (OurRawData == NULL) printf("Picture failed to load.\n");
p_state->user_data->textureID = CreateTexture2D(Width, Height, OurRawData);

You mention a while (TRUE) loop on page 63 as if it's already existing, but if you look back at the first code listing for the triangle on page 49, there is no while loop in the main function. 

My first reaction was to put the new code into the esMainLoop function (I mean, it's already called main loop, it has a while loop that terminates and it worked previously) which resulted in a program that was executing but displayed no picture, no compiler errors and none of the debug messages. So, without any errors I started looking for mistakes elsewhere and checked the code that was changed in this chapter so far against the book ... twice. Only when looking at the project file you uploaded for chapter 04 did I notice that you had placed a new while loop in the main function. 
So, to summarize, on page 61 you wrote "After the FileHandler add this code;"  which in my opinion should have been something like "Above the esMainLoop function in the main function at the bottom, add the following code:" and then on page 63 it should have said to add the new line below and put a while (TRUE) loop around it while also mentioning that execution of the program can now only be stopped from within Visual Studio by pressing the "Stop Debugging"-button.

Another thing, maybe for the next edition: Could you please highlight the changes you made to existing code?
Ah that's a good catch, thanks, I had assumed readers were referring to the supplied PhotoFrame code as a reference, I should have been much more explicit  and noted where to add the MyFiles  Filehandler;  line

it should look like this

int main(int argc, char *argv[])
    UserData user_data;
    bcm_host_init(); //RPI needs this        
    init_ogl(p_state, 1024, 768);
    p_state->user_data = &user_data;
    if (!Init(p_state))
        return 0;
    esRegisterDrawFunc(p_state, Draw);    
    MyFiles FileHandler;

And yes I also didn't explain the while loop (True) I will make some notes to change that in future editions and add it to the website errata.
It actually only needs the while (true) once you start to load multiple files since the single file load only really needs to load, then call the esMainLoop(p_state) call, before returning safely.

That ESMainloop code is legacy from the hello triangle code which is in all the standard tutorials,  but its not really a good way to do things as you move on, you'll see we slowly escape from it, and go to a more traditional game loop code which is cleaner and easier to follow.
It is currently designed to break from the debugger, it's not the kind of program you really want to run free. In fact all the projects are designed to be run as debugger demo's. But I am working on cleaner running  versions at the moment, with key escapes. It isn't too hard to put an escape system in, but you need to wait till you use the input handler to read keys.

I'll do my best to make notes of any changes, most of the changes are format based due to the small size of a written page and trying not to fill pages with source code, but there are one or 2 minor changes that developed over time, as well as simple errors on my part which I am happy to have pointed out and fix. As the book notes, be flexible, some things will be changed because I discovered errors on different platforms, and some things changed because there were other ways to do them.
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 

Errata page uipdated with this info and I've taken notes for a next edition (if there is one Big Grin)
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 


Forum Jump:

Users browsing this thread: 1 Guest(s)