Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New vgui support api #5

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port to new interface
a1batross committed May 2, 2023
commit 5848b3167cf4907ec87ca8f067141646e4be4b33
4 changes: 2 additions & 2 deletions vgui2_gameui.cpp
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ from your version.

namespace vgui_support
{
extern vguiapi_t *g_api;
};
extern vgui_support_api_t *g_api;
}

bool GameUIFuncs::IsKeyDown( const char *keyname, bool &isdown )
{
29 changes: 15 additions & 14 deletions vgui2_int.cpp
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@ from your version.

namespace vgui_support
{
extern vguiapi_t *g_api;
};
extern vgui_support_api_t *g_api;
} // namespace vgui_support

class RootPanel : public vgui2::Panel
{
@@ -89,17 +89,17 @@ static GameUIFuncs gameUIFuncs;

static inline void *LoadModule( const char *module )
{
return vgui_support::g_api->COM_LoadLibrary( module, false, false );
return vgui_support::g_api->LoadLibrary( module, false, false );
}

static inline CreateInterfaceFn GetFactory( void *module )
{
return (CreateInterfaceFn)vgui_support::g_api->COM_GetProcAddress( module, "CreateInterface" );
return (CreateInterfaceFn)vgui_support::g_api->GetProcAddress( module, "CreateInterface" );
}

static inline void UnloadModule( void *module )
{
vgui_support::g_api->COM_FreeLibrary( module );
vgui_support::g_api->FreeLibrary( module );
}

void BaseUI::Initialize( CreateInterfaceFn *factories, int count )
@@ -154,8 +154,8 @@ void BaseUI::Start( int width, int height )
char szMod[32];
vgui2::system()->GetCommandLineParamValue( "-game", szMod, sizeof( szMod ) );
char szLocalizeFile[260];

Q_snprintf( szLocalizeFile, sizeof( szLocalizeFile ), "resource/%s_%%language%%.txt", szMod );
szLocalizeFile[sizeof( szLocalizeFile ) - 1] = '\0';
vgui2::localize()->AddFile( vgui2::filesystem(), szLocalizeFile );

// TODO: Load localization from fallback directory
@@ -262,29 +262,30 @@ extern "C" EXPORT IBaseInterface *CreateInterface( const char *pName, int *pRetu
return nullptr;
}

void VGUI2_Startup( const char *clientlib, int width, int height )
void VGUI2_Startup( void *clientInstance, int width, int height )
{
if ( rootPanel == nullptr )
if( rootPanel == nullptr && clientInstance != nullptr )
{
fileSystemModule = LoadModule( "filesystem_stdio." OS_LIB_EXT );
auto fileSystemFactory = GetFactory( fileSystemModule );
fileSystem = (IVFileSystem009 *)fileSystemFactory( "VFileSystem009", nullptr );
fileSystem = (IVFileSystem009 *)fileSystemFactory( FILESYSTEM_INTERFACE_VERSION, nullptr );

CreateInterfaceFn factories[3];
factories[0] = CreateInterface;
factories[1] = fileSystemFactory;
factories[2] = GetFactory( LoadModule( clientlib ) );
factories[2] = GetFactory( clientInstance );

baseUI.Initialize( factories, 3 );
baseUI.Start( width, height );
}

rootPanel->SetBounds( 0, 0, width, height );
if( rootPanel != nullptr )
rootPanel->SetBounds( 0, 0, width, height );
}

void VGUI2_Shutdown( void )
{
if ( rootPanel == nullptr )
if( rootPanel == nullptr )
return;

baseUI.Shutdown();
@@ -294,13 +295,13 @@ void VGUI2_Shutdown( void )

void VGUI2_ScreenSize( int &width, int &height )
{
if ( rootPanel )
if( rootPanel )
rootPanel->GetSize( width, height );
}

bool VGUI2_UseVGUI1( void )
{
if ( clientVGUI )
if( clientVGUI )
return clientVGUI->UseVGUI1();
return true;
}
4 changes: 2 additions & 2 deletions vgui2_surf.cpp
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@ from your version.

namespace vgui_support
{
extern vguiapi_t *g_api;
};
extern vgui_support_api_t *g_api;
}

void VGUI2_ScreenSize( int &width, int &height );

64 changes: 35 additions & 29 deletions vgui_int.cpp
Original file line number Diff line number Diff line change
@@ -26,26 +26,29 @@ from your version.
#include "vgui_main.h"
#include "xash3d_types.h"

void VGUI2_Startup( const char *clientlib, int width, int height );
void VGUI2_Startup( void *clientlib, int width, int height );
void VGUI2_Shutdown( void );
bool VGUI2_UseVGUI1( void );
void VGUI2_Paint( void );

namespace vgui_support {

legacy_vguiapi_t *g_api;
vgui_support_api_t *g_api;

Panel *rootpanel = NULL;
CEngineSurface *surface = NULL;
CEngineApp staticApp;

void VGui_Startup( const char *clientlib, int width, int height )
void VGui_ClientStartup( void *clientInstance, int width, int height )
{
VGUI2_Startup( clientInstance, width, height );
}

void VGui_Startup( int width, int height )
{
if( rootpanel )
{
// The second call to VGui_Startup will be after client.dll Initialize
// Only start client VGUI2 now
VGUI2_Startup( clientlib, width, height );
VGUI2_Startup( NULL, width, height );
rootpanel->setSize( width, height );
return;
}
@@ -79,35 +82,31 @@ void VGui_Shutdown( void )

rootpanel = NULL;
surface = NULL;

VGUI2_Shutdown();
}

void VGui_Paint( void )
{
int w, h;

//if( cls.state != ca_active || !rootpanel )
// return;
if( !g_api->IsInGame() || !rootpanel )
return;

// setup the base panel to cover the screen
Panel *pVPanel = surface->getEmbeddedPanel();
if( !pVPanel ) return;
//SDL_GetWindowSize(host.hWnd, &w, &h);
//host.input_enabled = rootpanel->isVisible();
if( !pVPanel )
return;

rootpanel->getSize(w, h);
EnableScissor( true );

if ( VGUI2_UseVGUI1() )
if( VGUI2_UseVGUI1( ))
{
staticApp.externalTick ();

pVPanel->setBounds( 0, 0, w, h );
pVPanel->repaint();

// paint everything
// paint everything
pVPanel->paintTraverse();
}
else
@@ -123,19 +122,26 @@ void *VGui_GetPanel( void )
}
}

#ifdef INTERNAL_VGUI_SUPPORT
#define InitAPI InitVGUISupportAPI
#endif

extern "C" EXPORT void InitAPI( legacy_vguiapi_t *api )
static vgui_support_interface_t vguifuncs =
{
VGui_Startup,
VGui_Shutdown,
VGui_GetPanel,
VGui_Paint,
VGUI_Mouse,
VGUI_Key,
VGUI_MouseMove,
VGUI_TextInput,
VGui_ClientStartup
};

extern "C" int EXPORT GetVGUISupportAPI( int version, vgui_support_interface_t *iface, vgui_support_api_t *engfuncs )
{
g_api = api;
g_api->Startup = VGui_Startup;
g_api->Shutdown = VGui_Shutdown;
g_api->GetPanel = VGui_GetPanel;
g_api->Paint = VGui_Paint;
g_api->Mouse = VGUI_Mouse;
g_api->MouseMove = VGUI_MouseMove;
g_api->Key = VGUI_Key;
g_api->TextInput = VGUI_TextInput;
if( version != VGUI_SUPPORT_API_VERSION )
return 0;

g_api = engfuncs; // TODO: do not store the pointer
memcpy( iface, &vguifuncs, sizeof( vguifuncs ));

return VGUI_SUPPORT_API_VERSION;
}
2 changes: 1 addition & 1 deletion vgui_main.h
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ from your version.

namespace vgui_support
{
extern legacy_vguiapi_t *g_api;
extern vgui_support_api_t *g_api;

using namespace vgui;