Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ubermeowmix

Member Since 30 Jan 2010
Offline Last Active Sep 09 2016 04:36 AM

Posts I've Made

In Topic: SDL2 saving to binary clarification

05 January 2016 - 07:26 PM

RTFM helped with this one, it wasn't clear in the notes that the last variable taken was for the size of array's.

 

If anyone get's stuck I have included the code I wrote to illustrate a simple saving algorithm in SDL2

 

struct STRUCT_Data
{
    int INT_health;
    float FLOAT_speed;
};
 

void FUNC_create_and_save_struct_array_to_binary_SDL()
{
    ///SET THE PATH
    const char* CONST_CHAR_file_ref= "saves/SAVE_save_struct_array_to_binary_SDL2.bin";
 
    ///DECLARE THE VARS
    size_t INT_array_maximum= 3;
    size_t INT_array_maximum_loaded= 0; ///ONLY TO SHOW IT'S NOT USING THE PREVIOUS MAX
 
    ///FILL THE STRUCT WITH GENERIC CHUFF
    STRUCT_Data STRUCT_current_save[INT_array_maximum];
    STRUCT_current_save[0].INT_health= 10;
    STRUCT_current_save[0].FLOAT_speed= 33.333;
    STRUCT_current_save[1].INT_health= 255;
    STRUCT_current_save[1].FLOAT_speed= 3.0;
    STRUCT_current_save[2].INT_health= 6;
    STRUCT_current_save[2].FLOAT_speed= 1.55;
 
    ///SAVE THE DATA TO A BINARY FILE
    SDL_RWops *FILE_data_write = SDL_RWFromFile( CONST_CHAR_file_ref, "wb");
    if( FILE_data_write ==NULL )
    {
        ///ON FAIL RETURN NOTHING TO EXIT THE FUNCTION
        return;
    } else {
        SDL_RWwrite( FILE_data_write, &INT_array_maximum, sizeof(size_t), 1 );
        SDL_RWwrite( FILE_data_write, &STRUCT_current_save, sizeof(STRUCT_Data), INT_array_maximum );
        SDL_RWclose( FILE_data_write );
    }
 
    ///ZERO OUT THE VALUES SO YOU KNOW IT LOADS BACK IN OKAY
    STRUCT_current_save[0].INT_health= 0;
    STRUCT_current_save[0].FLOAT_speed= 0.0f;
    STRUCT_current_save[1].INT_health= 0;
    STRUCT_current_save[1].FLOAT_speed= 0.0f;
    STRUCT_current_save[2].INT_health= 0;
    STRUCT_current_save[2].FLOAT_speed= 0.0f;
 
    ///LOAD THE DATA BACK IN TO THE PROGRAM
    SDL_RWops *FILE_data_read = SDL_RWFromFile( CONST_CHAR_file_ref, "rb");
    if( FILE_data_read ==NULL )
    {
        ///ON FAIL RETURN NOTHING TO EXIT THE FUNCTION
        return;
    } else {
        SDL_RWread( FILE_data_read, &INT_array_maximum_loaded, sizeof(size_t), 1 );
        SDL_RWread( FILE_data_read, &STRUCT_current_save, sizeof(STRUCT_Data), INT_array_maximum_loaded );
        SDL_RWclose( FILE_data_read );
    }
 
    ///CHECK IT DISPLAYS OKAY
    std::cout << "STRUCT_current_save[0].INT_health: " << STRUCT_current_save[0].INT_health << std::endl;
    std::cout << "STRUCT_current_save[0].FLOAT_speed: " << STRUCT_current_save[0].FLOAT_speed << std::endl;
    std::cout << "STRUCT_current_save[1].INT_health: " << STRUCT_current_save[1].INT_health << std::endl;
    std::cout << "STRUCT_current_save[1].FLOAT_speed: " << STRUCT_current_save[1].FLOAT_speed << std::endl;
    std::cout << "STRUCT_current_save[2].INT_health: " << STRUCT_current_save[2].INT_health << std::endl;
    std::cout << "STRUCT_current_save[2].FLOAT_speed: " << STRUCT_current_save[2].FLOAT_speed << std::endl;
}


In Topic: Linker errors Eugh!

13 October 2015 - 12:37 PM

 if dealing with library linkage already gives you so much trouble.

 

 

I think this is a total lack of experience and blindly throwing myself into something I no one to talk to about or any where I can learn this stuff (or at least that's my perception at this time).


In Topic: Linker errors Eugh!

11 October 2015 - 03:56 AM

Do I need GLEW or can I just use SDL2 and run all input and sound through that? What's the difference between them as I'm not really sure why I'm wasting my time and sanity trying to get GLEW working.

 

Does anyone have any experience with them?


In Topic: Linker errors Eugh!

10 October 2015 - 08:06 AM

One more issue is that if you use the pre-compiled files then they might be for a different version of windows and still cause errors. 

 

e.g.

glewGetErrorString@4 could not be located


In Topic: Linker errors Eugh!

10 October 2015 - 07:31 AM

AH HA found out why!

 

This dude -link below- explains in his video that the GLEW files are precompiled for visual studio and not minGW so that's why they won't work:

 

He gives links to pre-compiled files -link below- for minGW so you can get it running, how frustrating!

http://www.grhmedia.com/glew.html


PARTNERS