Author Topic: SDL2 and how to close gui's?  (Read 13151 times)

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
SDL2 and how to close gui's?
« on: October 15, 2014, 11:59:30 pm »
So I found the keys that generate mouse buttons (like scroll wheel) and I guess middle click is how to activate the user block cube; but the only way I found to close that is to hit escape which is save and exit...  can escape be pre-empted by gui screens to close?

SDL2... I grabbed this, only took them 10 years to come out with it :)  Not a lot changes... have to change the type of 'GameEnv::screen' and use a different function to open the window; and unfortunatly the display info stuff is different, ended up just chopping that out for a fixed value from the settings file.... the swap call takes the GameEnv->screen(window) variable...

Code: [Select]
#define SDL_GL_SwapBuffers()             SDL_GL_SwapWindow( GameEnv->screen )

/* .... in ZGame... */
#ifdef SDL1
  SDL_Surface * screen;
#else
  SDL_Window * screen;
#endif


The sound system is different I guess; the last buffer is never cleared,
at the end of ZSound::MixAudio....

Code: [Select]
  if (nSounds) for (i = 0; i < Buffer_Len / 2; i++) ((Short *)stream)[i] = (Short)(SoundBuffer[i]);
  else
  memset(stream, 0, len);
otherwise stream is not cleared when there were no sounds to mix, and that block keeps looping.

---------
removed a lot of references to including SDL, since it's included in ZGame.h anyway and seems most everything ends up including that.
----------

how do I exit a gui dialog?   is it easy to add a X button?

----------
The method for the mouse is different; but a simple define can fix that

Code: [Select]
#define SDL_WM_GrabInput      SDL_SetRelativeMouseMode
#define SDL_GRAB_ON          SDL_TRUE
#define SDL_GRAB_OFF           SDL_FALSE

// otherwise warp mouse takes the window/screen as parameter
#define SDL_WarpMouse SDL_WarpMouseGlobal

----------
Some missing/modified keyboard handling/mapping.  Have to take the sym & 0xFF a lot of places because they set a high-bit in it (1<<30)

Code: [Select]
#define SDLK_KP0 SDLK_KP_0
#define SDLK_KP1 SDLK_KP_1
#define SDLK_KP2 SDLK_KP_2
#define SDLK_KP3 SDLK_KP_3
#define SDLK_KP4 SDLK_KP_4
#define SDLK_KP5 SDLK_KP_5
#define SDLK_KP6 SDLK_KP_6
#define SDLK_KP7 SDLK_KP_7
#define SDLK_KP8 SDLK_KP_8
#define SDLK_KP9 SDLK_KP_9

---------------
SDL2 also changes how the scroll wheel is handled, instead of passing it as a button it's an axis, and they support horizontal/vertical scroll...  so my scroll wheel is broken for changing items, but I found the keys for now.

olive

  • Administrator
  • Full Member
  • *****
  • Posts: 149
    • View Profile
Re: SDL2 and how to close gui's?
« Reply #1 on: October 16, 2014, 02:05:41 am »
Hi d3x0r and welcome,  :)

What you do seems very interesting.

We will look at the details in the next few day to respond to your questions.

Some informations we can give you quickly :

- The inventory "I" key is used to close all GUI dialog boxes. Can certainly be improved.

- All GUI elements : Windows, Gadgets, Buttons, etc are nested boxes of ZFrame type class or inheriting child classes. To create a button like a close button, a ZTileFrame should be a good choice. It must be added to the parent ZFrame for display and use.

- Buttons addition to GUI, GUI definitions and events are processed in the Window classes ZGameWindow_* classes. These classes are good exemples on how to make a dialog box in Blackvoxel.

Thanks for signaling some problems on sound server.

We'll try to give you more detailled informations in the next days. Some docs on Blackvoxel internals need to be written and we'll try to do that gradually with time.

Thanks for you interest in Blackvoxel,
The Blackvoxel Team

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: SDL2 and how to close gui's?
« Reply #2 on: October 16, 2014, 03:56:09 am »
I key; great :)

-----
(SDL2 changes; SDL_CreateThread takes a name now (of the thread proc itself, instead of "thread_proc" maybe)
---------
My games aren't saving.
my last world2 I died, and saved hit escape and got out before being respawned.  Now I get console messags that say 'fatal fall...' something but don't die.   And when I move a couple steps and quit, it always starts where it was, including old worlds... hmm the binary download saves... wonder what I broke.


d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: SDL2 and how to close gui's?
« Reply #3 on: October 16, 2014, 08:47:48 pm »
I also threw together a cmake build script for the project since the make system was simple enough.
Need an option to set things like

Code: [Select]
OPTION( COMPILEOPTION_ALLOWSAVEPLAYERSTATE "Allow Save Player State" ON )

Oh I see; I should have traced that back to its actual defintiion; assumed it was just undefined....

:) DEVELOPPEMENT_ON :) is spelled wrong
I guess the option should be more like

Code: [Select]
OPTION( DEVELOPPEMENT_FORCE_DEV "Build dev mode (disable save)" OFF )
OPTION( COMPILEOPTION_DEMO "Build demo mode (enable save)" ON )

or something....

olive

  • Administrator
  • Full Member
  • *****
  • Posts: 149
    • View Profile
Re: SDL2 and how to close gui's?
« Reply #4 on: October 16, 2014, 08:53:47 pm »
My games aren't saving.
my last world2 I died, and saved hit escape and got out before being respawned.  Now I get console messags that say 'fatal fall...' something but don't die.   And when I move a couple steps and quit, it always starts where it was, including old worlds... hmm the binary download saves... wonder what I broke.

Hum, it could be related to development settings that may be enabled and could disable save.

Look at the ACompileSettings.h file for master switches. At line 76, change :

COMPILEOPTION_ALLOWSAVE 0

with :

COMPILEOPTION_ALLOWSAVE 1

Be sure to change this on line 76 only.

The Blackvoxel Team

d3x0r

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: SDL2 and how to close gui's?
« Reply #5 on: October 17, 2014, 04:44:23 am »

Break out SaveWorld from End_PhysicsEngine()....

Code: [Select]
void ZGame::SaveWorld(  )
{
  ZStream_SpecialRamStream Stream;
  ZStream_File FileStream;
  ZString FileName;
  if (COMPILEOPTION_USEHOMEDIRSTORAGE)
  {
    FileName = ZStream_File::Get_Directory_UserData();
    FileName.AddToPath(COMPILEOPTION_SAVEFOLDERNAME);
  }
  FileName.AddToPath("Universes").AddToPath((ZString)UniverseNum).AddToPath("PlayerInfo.dat");
  FileStream.SetFileName(FileName.String);
  if (FileStream.OpenWrite())
  {
    Stream.SetStream(&FileStream);

    PhysicEngine->GetSelectedActor()->Save(&Stream);
    Stream.FlushBuffer();
    Stream.Close();
    FileStream.Close();
  }
/*
  // Inventory Saving
  char Buffer[1024];
  sprintf(Buffer, "%s/%ld/PlayerInfo.dat", UniverseNum);
  PhysicEngine->GetSelectedActor()->Inventory->Save(Buffer);
*/

}

bool ZGame::End_PhysicEngine()
{

  // Save Physic engine actors

#if COMPILEOPTION_ALLOWSAVEPLAYERSTATE == 1
  SaveWorld( );
#endif


  if (PhysicEngine) delete PhysicEngine;
  PhysicEngine = 0;
  Initialized_PhysicEngine = false;
  return(true);
}

add save world key F6...
Code: [Select]
case SDLK_F6 & 0xFF:
GameEnv->GameWindow_Advertising->Advertise("Saving....", ZGameWindow_Advertising::VISIBILITY_HIGH,0,1000,500);
GameEnv->SaveWorld( );
break;

disable auto save :)