mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
Compare commits
28 Commits
continuous
...
continuous
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f819a2fde | ||
|
|
3251b68df5 | ||
|
|
3ac8ad9484 | ||
|
|
b9ca0d4563 | ||
|
|
dcb3da53b0 | ||
|
|
e68b19ed1a | ||
|
|
14c7a84482 | ||
|
|
c1d1aa6787 | ||
|
|
bee81e9723 | ||
|
|
1bfb6c560a | ||
|
|
24d6f1788a | ||
|
|
fb95cc9a97 | ||
|
|
b949da291e | ||
|
|
2ecbe5b67e | ||
|
|
6634e0487c | ||
|
|
7d61b5317c | ||
|
|
201258dc9e | ||
|
|
0330569537 | ||
|
|
a1ab84a2ca | ||
|
|
2d79f3ef7a | ||
|
|
99a7e9ad87 | ||
|
|
02b8037f33 | ||
|
|
fc55a685e3 | ||
|
|
b76a75d6b4 | ||
|
|
a251600c8a | ||
|
|
c551aefd77 | ||
|
|
f343f0da41 | ||
|
|
6d318a4102 |
2
3rdparty/mainui
vendored
2
3rdparty/mainui
vendored
Submodule 3rdparty/mainui updated: d6a54bbf0c...adb3e413ec
@@ -133,22 +133,8 @@ Available in mod archive on ModDB - https://www.moddb.com/mods/overturn
|
||||
## Oz Deathmatch
|
||||
Mirrored on github - https://github.com/nekonomicon/OZDM
|
||||
|
||||
## Spirit of Half-Life
|
||||
[Logic&Trick's](https://github.com/LogicAndTrick) mirror - https://files.logic-and-trick.com/#/Half-Life/Mods/Spirit%20of%20Half-Life
|
||||
|
||||
## Threewave CTF
|
||||
*Unfinished mod by Valve Software*
|
||||
|
||||
Available in Valve's Half-Life repository with Deathmatch Classic sources - https://github.com/ValveSoftware/halflife/tree/master/dmc
|
||||
|
||||
## Trinity Render
|
||||
Available on ModDB: https://www.moddb.com/mods/half-life-episode-two/downloads/trinity-rendering-engine-v308f
|
||||
|
||||
## Tyrian: Ground Assault
|
||||
Available on ModDB: https://www.moddb.com/mods/tyriangroundassault/downloads/tyrianga-v1-0-src
|
||||
|
||||
## Paranoia
|
||||
Available on ModDB: https://www.moddb.com/mods/paranoia/downloads/paranoia-toolkit
|
||||
Available on ModDB - https://www.moddb.com/mods/paranoia/downloads/paranoia-toolkit
|
||||
|
||||
## Paranoia 2: The Savior
|
||||
Prealpha, mirrored on github - https://github.com/a1batross/Paranoia2_ancient
|
||||
@@ -163,12 +149,37 @@ Was found on HLFX - http://hlfx.ru/forum/showthread.php?s=2c892dfc52f72be52a89c3
|
||||
## Ricochet
|
||||
Available in Valve's Half-Life repository - https://github.com/ValveSoftware/halflife/tree/master/ricochet
|
||||
|
||||
## Spirit of Half-Life
|
||||
[Logic&Trick's](https://github.com/LogicAndTrick) mirror - https://files.logic-and-trick.com/#/Half-Life/Mods/Spirit%20of%20Half-Life
|
||||
|
||||
## The Wastes
|
||||
Version 1.5: mirrored on code.idtech.space - https://code.idtech.space/vera/halflife-thewastes-sdk
|
||||
|
||||
## Threewave CTF
|
||||
*Unfinished mod by Valve Software*
|
||||
|
||||
Available in Valve's Half-Life repository with Deathmatch Classic sources - https://github.com/ValveSoftware/halflife/tree/master/dmc
|
||||
|
||||
## Trinity Render
|
||||
Available on ModDB - https://www.moddb.com/mods/half-life-episode-two/downloads/trinity-rendering-engine-v308f
|
||||
|
||||
## Tyrian: Ground Assault
|
||||
Available on ModDB - https://www.moddb.com/mods/tyriangroundassault/downloads/tyrianga-v1-0-src
|
||||
|
||||
## Wasteland
|
||||
Mirrored on code.idtech.space - https://code.idtech.space/vera/halflife-wasteland-sdk
|
||||
|
||||
## Wizard Wars
|
||||
Download page on official site - http://www.thothie.com/ww/
|
||||
|
||||
## XashXT
|
||||
Mirrored on github - https://github.com/a1batross/XashXT_original
|
||||
|
||||
## Xen-Warrior
|
||||
*Source code is a part of Spirit of Half-Life 1.0-1.2 under XENWARRIOR macro*
|
||||
|
||||
[Logic&Trick's](https://github.com/LogicAndTrick) mirror - https://files.logic-and-trick.com/#/Half-Life/Mods/Spirit%20of%20Half-Life
|
||||
|
||||
## Zombie-X
|
||||
Available in mod archive on ModDB - https://www.moddb.com/mods/zombie-x-10-final/downloads/zombie-x-10-dle-beta6-last-version
|
||||
|
||||
@@ -190,12 +201,12 @@ malortie's recreation - https://github.com/malortie/hl-aom
|
||||
Branch **aom** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/aom
|
||||
|
||||
## Afraid of Monsters: Director's cut
|
||||
Reverse-engineered code, branch **aomdc** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/aomdc
|
||||
Reverse-engineered code: branch **aomdc** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/aomdc
|
||||
|
||||
## Azure Sheep
|
||||
malortie's recreation - https://github.com/malortie/hl-asheep
|
||||
|
||||
Reverse-engineered code, branch **asheep** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/asheep
|
||||
Reverse-engineered code: branch **asheep** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/asheep
|
||||
|
||||
## Big Lolly
|
||||
malortie's recreation - https://github.com/malortie/hl-biglolly
|
||||
@@ -232,12 +243,17 @@ Recreation by lostgamer aka nillerusr - https://github.com/LostGamerHL/crack_lif
|
||||
## Escape from the Darkness
|
||||
malortie's recreation - https://github.com/malortie/hl-eftd
|
||||
|
||||
Reverse-engineered code, branch **eftd** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/eftd
|
||||
Reverse-engineered code: branch **eftd** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/eftd
|
||||
|
||||
## Half-Life: Black Guard
|
||||
*This mod uses dlls from Cleaner's Adventures*
|
||||
|
||||
Branch **CAd** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/CAd
|
||||
|
||||
## Half-Life: Blue Shift
|
||||
Unkle Mike's recreation - https://hlfx.ru/forum/showthread.php?s=&threadid=5253
|
||||
|
||||
Reverse-engineered code, branch **bshift** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/bshift
|
||||
Reverse-engineered code: branch **bshift** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/bshift
|
||||
|
||||
## Half-Life: Induction
|
||||
Branch **induction** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/induction
|
||||
@@ -245,12 +261,12 @@ Branch **induction** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/
|
||||
## Half-Life: Opposing Force
|
||||
Recreation by lostgamer aka nillerusr - https://github.com/LostGamerHL/hlsdk-xash3d
|
||||
|
||||
Reverse-engineered code, clean branch **opfor** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/opfor
|
||||
Reverse-engineered code: clean branch **opfor** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/opfor
|
||||
|
||||
Spirit of Half Life: Opposing-Force Edition - https://github.com/Hammermaps-DEV/SOHL-V1.9-Opposing-Force-Edition
|
||||
|
||||
## Half-Life: Rebellion
|
||||
Reverse-engineered code, branch **rebellion** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/rebellion
|
||||
Reverse-engineered code: branch **rebellion** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/rebellion
|
||||
|
||||
## Half-Life: Urbicide
|
||||
Branch **hl_urbicide** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/hl_urbicide
|
||||
@@ -258,7 +274,7 @@ Branch **hl_urbicide** in hlsdk-portable - https://github.com/FWGS/hlsdk-portabl
|
||||
## Half-Life: Visitors
|
||||
malortie's recreation - https://github.com/malortie/hl-visitors
|
||||
|
||||
Reverse-engineered code, branch **visitors** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/visitors
|
||||
Reverse-engineered code: branch **visitors** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/visitors
|
||||
|
||||
## Half-Secret
|
||||
Branch **half-secret** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/half-secret
|
||||
@@ -271,18 +287,18 @@ Branch **noffice** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tr
|
||||
## Poke 646
|
||||
malortie's recreation - https://github.com/malortie/hl-poke646
|
||||
|
||||
Reverse-engineered code, branch **poke646** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/poke646
|
||||
Reverse-engineered code: branch **poke646** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/poke646
|
||||
|
||||
## Poke 646: Vendetta
|
||||
malortie's recreation - https://github.com/malortie/hl-poke646-vendetta
|
||||
|
||||
Reverse-engineered code, branch **poke646_vendetta** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/poke646_vendetta
|
||||
Reverse-engineered code: branch **poke646_vendetta** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/poke646_vendetta
|
||||
|
||||
## Residual Life
|
||||
Reverse-engineered code, branch **residual_point** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/residual_point
|
||||
Reverse-engineered code: branch **residual_point** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/residual_point
|
||||
|
||||
## Residual Point
|
||||
Reverse-engineered code, branch **residual_point** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/residual_point
|
||||
Reverse-engineered code: branch **residual_point** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/residual_point
|
||||
|
||||
## Sewer Beta
|
||||
Branch **sewer_beta** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/sewer_beta
|
||||
@@ -293,12 +309,12 @@ Reverse-engineered code by Velaron - https://github.com/Velaron/tf15-client
|
||||
## The Gate
|
||||
malortie's recreation - https://github.com/malortie/hl-thegate
|
||||
|
||||
Reverse-engineered code, branch **thegate** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/thegate
|
||||
Reverse-engineered code: branch **thegate** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/thegate
|
||||
|
||||
## They Hunger
|
||||
malortie's recreation - https://github.com/malortie/hl-theyhunger
|
||||
|
||||
Reverse-engineered code, branch **theyhunger** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/theyhunger
|
||||
Reverse-engineered code: branch **theyhunger** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/theyhunger
|
||||
|
||||
They Hunger: Tactical - https://www.moddb.com/mods/they-hunger-tactical/downloads/tht-source-code-documentation
|
||||
|
||||
@@ -341,16 +357,22 @@ Branch **half-screwed** in hlsdk-portable - https://github.com/FWGS/hlsdk-portab
|
||||
Port to Linux - https://github.com/fmoraw/NS
|
||||
|
||||
## Spirit of Half-Life
|
||||
Version 1.2, branch **sohl1.2** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/sohl1.2
|
||||
Version 1.2: branch **sohl1.2** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/sohl1.2
|
||||
|
||||
## Swiss Cheese Halloween 2002
|
||||
Just more playable version by malortie - https://github.com/malortie/hl-shall
|
||||
|
||||
Branch **halloween** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/halloween
|
||||
|
||||
## The Wastes
|
||||
Version 1.5: Port to Linux - https://git.mentality.rip/a1batross/halflife-thewastes-sdk
|
||||
|
||||
## Threewave CTF
|
||||
Branch **dmc** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/dmc
|
||||
|
||||
## Xen-Warrior
|
||||
Branch **sohl1.2** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/sohl1.2
|
||||
|
||||
## Zombie-X
|
||||
Branch **zombie-x** in hlsdk-portable - https://github.com/FWGS/hlsdk-portable/tree/zombie-x
|
||||
|
||||
|
||||
@@ -9,7 +9,20 @@ NOTE: number at end of pixelformat name it's a total bitscount e.g. PF_RGB_24 ==
|
||||
========================================================================
|
||||
*/
|
||||
#define ImageRAW( type ) (type == PF_RGBA_32 || type == PF_BGRA_32 || type == PF_RGB_24 || type == PF_BGR_24 || type == PF_LUMINANCE)
|
||||
#define ImageDXT( type ) (type == PF_DXT1 || type == PF_DXT3 || type == PF_DXT5 || type == PF_ATI2 || type == PF_BC6H_SIGNED || type == PF_BC6H_UNSIGNED || type == PF_BC7)
|
||||
#define ImageCompressed( type ) \
|
||||
( type == PF_DXT1 \
|
||||
|| type == PF_DXT3 \
|
||||
|| type == PF_DXT5 \
|
||||
|| type == PF_ATI2 \
|
||||
|| type == PF_BC4_SIGNED \
|
||||
|| type == PF_BC4_UNSIGNED \
|
||||
|| type == PF_BC5_SIGNED \
|
||||
|| type == PF_BC5_UNSIGNED \
|
||||
|| type == PF_BC6H_SIGNED \
|
||||
|| type == PF_BC6H_UNSIGNED \
|
||||
|| type == PF_BC7_UNORM \
|
||||
|| type == PF_BC7_SRGB \
|
||||
|| type == PF_KTX2_RAW )
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -25,9 +38,15 @@ typedef enum
|
||||
PF_DXT3, // s3tc DXT3/BC2 format
|
||||
PF_DXT5, // s3tc DXT5/BC3 format
|
||||
PF_ATI2, // latc ATI2N/BC5 format
|
||||
PF_BC4_SIGNED,
|
||||
PF_BC4_UNSIGNED,
|
||||
PF_BC5_SIGNED,
|
||||
PF_BC5_UNSIGNED,
|
||||
PF_BC6H_SIGNED, // bptc BC6H signed FP16 format
|
||||
PF_BC6H_UNSIGNED, // bptc BC6H unsigned FP16 format
|
||||
PF_BC7, // bptc BC7 format
|
||||
PF_BC7_UNORM, // bptc BC7 format
|
||||
PF_BC7_SRGB,
|
||||
PF_KTX2_RAW, // Raw KTX2 data, used for yet unsupported KTX2 subformats
|
||||
PF_TOTALCOUNT, // must be last
|
||||
} pixformat_t;
|
||||
|
||||
@@ -50,6 +69,7 @@ typedef enum
|
||||
IL_LOAD_DECAL = BIT(5), // special mode for load gradient decals
|
||||
IL_OVERVIEW = BIT(6), // overview required some unque operations
|
||||
IL_LOAD_PLAYER_DECAL = BIT(7), // special mode for player decals
|
||||
IL_KTX2_RAW = BIT(8), // renderer can consume raw KTX2 files (e.g. ref_vk)
|
||||
} ilFlags_t;
|
||||
|
||||
// goes into rgbdata_t->encode
|
||||
|
||||
@@ -86,16 +86,19 @@ typedef uint64_t longtime_t;
|
||||
#endif
|
||||
#define _format(x) __attribute__((format(printf, x, x+1)))
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#define NONNULL __attribute__((nonnull))
|
||||
#elif defined(_MSC_VER)
|
||||
#define EXPORT __declspec( dllexport )
|
||||
#define GAME_EXPORT
|
||||
#define _format(x)
|
||||
#define NORETURN
|
||||
#define NONNULL
|
||||
#else
|
||||
#define EXPORT
|
||||
#define GAME_EXPORT
|
||||
#define _format(x)
|
||||
#define NORETURN
|
||||
#define NONNULL
|
||||
#endif
|
||||
|
||||
#if ( __GNUC__ >= 3 )
|
||||
|
||||
@@ -3336,6 +3336,9 @@ static void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags,
|
||||
if( remote_address->type != NA_IPX && remote_address->type != NA_BROADCAST_IPX )
|
||||
return; // IPX no longer support
|
||||
|
||||
if( request == NETAPI_REQUEST_SERVERLIST )
|
||||
return; // no support for server list requests
|
||||
|
||||
// find a free request
|
||||
for( i = 0; i < MAX_REQUESTS; i++ )
|
||||
{
|
||||
@@ -3372,28 +3375,9 @@ static void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags,
|
||||
nr->resp.remote_address = *remote_address;
|
||||
nr->flags = flags;
|
||||
|
||||
if( request == NETAPI_REQUEST_SERVERLIST )
|
||||
{
|
||||
char fullquery[512];
|
||||
size_t len;
|
||||
|
||||
len = CL_BuildMasterServerScanRequest( fullquery, sizeof( fullquery ), false );
|
||||
|
||||
// make sure that port is specified
|
||||
if( !nr->resp.remote_address.port )
|
||||
nr->resp.remote_address.port = MSG_BigShort( PORT_MASTER );
|
||||
|
||||
// grab the list from the master server
|
||||
NET_SendPacket( NS_CLIENT, len, fullquery, nr->resp.remote_address );
|
||||
clgame.request_type = NET_REQUEST_CLIENT;
|
||||
clgame.master_request = nr; // holds the master request unitl the master acking
|
||||
}
|
||||
else
|
||||
{
|
||||
// local servers request
|
||||
Q_snprintf( req, sizeof( req ), "netinfo %i %i %i", PROTOCOL_VERSION, context, request );
|
||||
Netchan_OutOfBandPrint( NS_CLIENT, nr->resp.remote_address, "%s", req );
|
||||
}
|
||||
// local servers request
|
||||
Q_snprintf( req, sizeof( req ), "netinfo %i %i %i", PROTOCOL_VERSION, context, request );
|
||||
Netchan_OutOfBandPrint( NS_CLIENT, nr->resp.remote_address, "%s", req );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3421,13 +3405,6 @@ static void GAME_EXPORT NetAPI_CancelRequest( int context )
|
||||
nr->pfnFunc( &nr->resp );
|
||||
}
|
||||
|
||||
if( clgame.net_requests[i].resp.type == NETAPI_REQUEST_SERVERLIST && &clgame.net_requests[i] == clgame.master_request )
|
||||
{
|
||||
if( clgame.request_type == NET_REQUEST_CLIENT )
|
||||
clgame.request_type = NET_REQUEST_CANCEL;
|
||||
clgame.master_request = NULL;
|
||||
}
|
||||
|
||||
memset( &clgame.net_requests[i], 0, sizeof( net_request_t ));
|
||||
break;
|
||||
}
|
||||
@@ -3456,8 +3433,6 @@ void GAME_EXPORT NetAPI_CancelAllRequests( void )
|
||||
}
|
||||
|
||||
memset( clgame.net_requests, 0, sizeof( clgame.net_requests ));
|
||||
clgame.request_type = NET_REQUEST_CANCEL;
|
||||
clgame.master_request = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -92,7 +92,7 @@ client_t cl;
|
||||
client_static_t cls;
|
||||
clgame_static_t clgame;
|
||||
|
||||
void CL_InternetServers_f( void );
|
||||
static void CL_SendMasterServerScanRequest( void );
|
||||
|
||||
//======================================================================
|
||||
int GAME_EXPORT CL_Active( void )
|
||||
@@ -1081,7 +1081,7 @@ void CL_CheckForResend( void )
|
||||
qboolean bandwidthTest;
|
||||
|
||||
if( cls.internetservers_wait )
|
||||
CL_InternetServers_f();
|
||||
CL_SendMasterServerScanRequest();
|
||||
|
||||
// if the local server is running and we aren't then connect
|
||||
if( cls.state == ca_disconnected && SV_Active( ))
|
||||
@@ -1574,10 +1574,10 @@ void CL_LocalServers_f( void )
|
||||
CL_BuildMasterServerScanRequest
|
||||
=================
|
||||
*/
|
||||
size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat )
|
||||
static size_t NONNULL CL_BuildMasterServerScanRequest( char *buf, size_t size, uint32_t *key, qboolean nat, const char *filter )
|
||||
{
|
||||
size_t remaining;
|
||||
char *info;
|
||||
char *info, temp[32];
|
||||
|
||||
if( unlikely( size < sizeof( MS_SCAN_REQUEST )))
|
||||
return 0;
|
||||
@@ -1587,7 +1587,9 @@ size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat )
|
||||
info = buf + sizeof( MS_SCAN_REQUEST ) - 1;
|
||||
remaining = size - sizeof( MS_SCAN_REQUEST );
|
||||
|
||||
info[0] = 0;
|
||||
Q_strncpy( info, filter, remaining );
|
||||
|
||||
*key = COM_RandomLong( 0, 0x7FFFFFFF );
|
||||
|
||||
#ifndef XASH_ALL_SERVERS
|
||||
Info_SetValueForKey( info, "gamedir", GI->gamefolder, remaining );
|
||||
@@ -1595,9 +1597,24 @@ size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat )
|
||||
Info_SetValueForKey( info, "clver", XASH_VERSION, remaining ); // let master know about client version
|
||||
Info_SetValueForKey( info, "nat", nat ? "1" : "0", remaining );
|
||||
|
||||
Q_snprintf( temp, sizeof( temp ), "%x", *key );
|
||||
Info_SetValueForKey( info, "key", temp, remaining );
|
||||
|
||||
return sizeof( MS_SCAN_REQUEST ) + Q_strlen( info );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CL_SendMasterServerScanRequest
|
||||
=================
|
||||
*/
|
||||
static void CL_SendMasterServerScanRequest( void )
|
||||
{
|
||||
cls.internetservers_wait = NET_SendToMasters( NS_CLIENT,
|
||||
cls.internetservers_query_len, cls.internetservers_query );
|
||||
cls.internetservers_pending = true;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CL_InternetServers_f
|
||||
@@ -1605,26 +1622,24 @@ CL_InternetServers_f
|
||||
*/
|
||||
void CL_InternetServers_f( void )
|
||||
{
|
||||
char fullquery[512];
|
||||
size_t len;
|
||||
qboolean nat = cl_nat.value != 0.0f;
|
||||
uint32_t key;
|
||||
|
||||
len = CL_BuildMasterServerScanRequest( fullquery, sizeof( fullquery ), nat );
|
||||
if( Cmd_Argc( ) > 2 || ( Cmd_Argc( ) == 2 && !Info_IsValid( Cmd_Argv( 1 ))))
|
||||
{
|
||||
Con_Printf( S_USAGE "internetservers [filter]\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
cls.internetservers_query_len = CL_BuildMasterServerScanRequest(
|
||||
cls.internetservers_query, sizeof( cls.internetservers_query ),
|
||||
&cls.internetservers_key, nat, Cmd_Argv( 1 ));
|
||||
|
||||
Con_Printf( "Scanning for servers on the internet area...\n" );
|
||||
|
||||
NET_Config( true, true ); // allow remote
|
||||
|
||||
cls.internetservers_wait = NET_SendToMasters( NS_CLIENT, len, fullquery );
|
||||
cls.internetservers_pending = true;
|
||||
|
||||
if( !cls.internetservers_wait )
|
||||
{
|
||||
// now we clearing the vgui request
|
||||
if( clgame.master_request != NULL )
|
||||
memset( clgame.master_request, 0, sizeof( net_request_t ));
|
||||
clgame.request_type = NET_REQUEST_GAMEUI;
|
||||
}
|
||||
CL_SendMasterServerScanRequest();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2152,6 +2167,25 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
|
||||
return;
|
||||
}
|
||||
|
||||
// check the extra header
|
||||
if( MSG_ReadByte( msg ) == 0x7f )
|
||||
{
|
||||
uint32_t key = MSG_ReadDword( msg );
|
||||
|
||||
if( cls.internetservers_key != key )
|
||||
{
|
||||
Con_Printf( S_WARN "unexpected server list packet from %s (invalid key)\n", NET_AdrToString( from ));
|
||||
return;
|
||||
}
|
||||
|
||||
MSG_ReadByte( msg ); // reserved byte
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_Printf( S_WARN "invalid server list packet from %s (missing extra header)\n", NET_AdrToString( from ));
|
||||
return;
|
||||
}
|
||||
|
||||
// serverlist got from masterserver
|
||||
while( MSG_GetNumBitsLeft( msg ) > 8 )
|
||||
{
|
||||
@@ -2161,58 +2195,10 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
|
||||
|
||||
// list is ends here
|
||||
if( !servadr.port )
|
||||
{
|
||||
if( clgame.request_type == NET_REQUEST_CLIENT && clgame.master_request != NULL )
|
||||
{
|
||||
net_request_t *nr = clgame.master_request;
|
||||
net_adrlist_t *list, **prev;
|
||||
|
||||
// setup the answer
|
||||
nr->resp.remote_address = from;
|
||||
nr->resp.error = NET_SUCCESS;
|
||||
nr->resp.ping = host.realtime - nr->timesend;
|
||||
|
||||
if( nr->timeout <= host.realtime )
|
||||
SetBits( nr->resp.error, NET_ERROR_TIMEOUT );
|
||||
|
||||
Con_Printf( "serverlist call: %s\n", NET_AdrToString( from ));
|
||||
nr->pfnFunc( &nr->resp );
|
||||
|
||||
// throw the list, now it will be stored in user area
|
||||
prev = (net_adrlist_t**)&nr->resp.response;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
list = *prev;
|
||||
if( !list ) break;
|
||||
|
||||
// throw out any variables the game created
|
||||
*prev = list->next;
|
||||
Mem_Free( list );
|
||||
}
|
||||
memset( nr, 0, sizeof( *nr )); // done
|
||||
clgame.request_type = NET_REQUEST_CANCEL;
|
||||
clgame.master_request = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if( clgame.request_type == NET_REQUEST_CLIENT && clgame.master_request != NULL )
|
||||
{
|
||||
net_request_t *nr = clgame.master_request;
|
||||
net_adrlist_t *list;
|
||||
|
||||
// adding addresses into list
|
||||
list = Z_Malloc( sizeof( *list ));
|
||||
list->remote_address = servadr;
|
||||
list->next = nr->resp.response;
|
||||
nr->resp.response = list;
|
||||
}
|
||||
else if( clgame.request_type == NET_REQUEST_GAMEUI )
|
||||
{
|
||||
NET_Config( true, false ); // allow remote
|
||||
Netchan_OutOfBandPrint( NS_CLIENT, servadr, "info %i", PROTOCOL_VERSION );
|
||||
}
|
||||
NET_Config( true, false ); // allow remote
|
||||
Netchan_OutOfBandPrint( NS_CLIENT, servadr, "info %i", PROTOCOL_VERSION );
|
||||
}
|
||||
|
||||
if( cls.internetservers_pending )
|
||||
@@ -2261,10 +2247,13 @@ void CL_ReadNetMessage( void )
|
||||
|
||||
while( CL_GetMessage( net_message_buffer, &curSize ))
|
||||
{
|
||||
if( cls.legacymode && *((int *)&net_message_buffer) == 0xFFFFFFFE )
|
||||
const int split_header = LittleLong( 0xFFFFFFFE );
|
||||
if( cls.legacymode && !memcmp( &split_header, net_message_buffer, sizeof( split_header )))
|
||||
{
|
||||
// Will rewrite existing packet by merged
|
||||
if( !NetSplit_GetLong( &cls.netchan.netsplit, &net_from, net_message_buffer, &curSize ) )
|
||||
continue;
|
||||
}
|
||||
|
||||
MSG_Init( &net_message, "ServerData", net_message_buffer, curSize );
|
||||
|
||||
|
||||
@@ -1534,7 +1534,8 @@ void CL_SendConsistencyInfo( sizebuf_t *msg )
|
||||
{
|
||||
case force_exactfile:
|
||||
MD5_HashFile( md5, filename, NULL );
|
||||
pc->value = *(int *)md5;
|
||||
memcpy( &pc->value, md5, sizeof( pc->value ));
|
||||
LittleLongSW( pc->value );
|
||||
|
||||
if( user_changed_diskfile )
|
||||
MSG_WriteUBitLong( msg, 0, 32 );
|
||||
|
||||
@@ -726,6 +726,7 @@ void SCR_VidInit( void )
|
||||
|
||||
// restart console size
|
||||
Con_VidInit ();
|
||||
Touch_NotifyResize();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -423,13 +423,6 @@ typedef struct
|
||||
float applied_angle;
|
||||
} screen_shake_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NET_REQUEST_CANCEL = 0, // request was cancelled for some reasons
|
||||
NET_REQUEST_GAMEUI, // called from GameUI
|
||||
NET_REQUEST_CLIENT, // called from Client
|
||||
} net_request_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
net_response_t resp;
|
||||
@@ -491,9 +484,7 @@ typedef struct
|
||||
client_textmessage_t *titles; // title messages, not network messages
|
||||
int numTitles;
|
||||
|
||||
net_request_type_t request_type; // filter the requests
|
||||
net_request_t net_requests[MAX_REQUESTS]; // no reason to keep more
|
||||
net_request_t *master_request; // queued master request
|
||||
|
||||
efrag_t *free_efrags; // linked efrags
|
||||
cl_entity_t viewent; // viewmodel
|
||||
@@ -627,7 +618,10 @@ typedef struct
|
||||
file_t *demofile;
|
||||
file_t *demoheader; // contain demo startup info in case we record a demo on this level
|
||||
qboolean internetservers_wait; // internetservers is waiting for dns request
|
||||
qboolean internetservers_pending; // internetservers is waiting for dns request
|
||||
qboolean internetservers_pending; // if true, clean master server pings
|
||||
uint32_t internetservers_key; // compare key to validate master server reply
|
||||
char internetservers_query[512]; // cached query
|
||||
uint32_t internetservers_query_len;
|
||||
|
||||
// legacy mode support
|
||||
qboolean legacymode; // one-way 48 protocol compatibility
|
||||
@@ -765,7 +759,6 @@ int CL_IsDevOverviewMode( void );
|
||||
void CL_PingServers_f( void );
|
||||
void CL_SignonReply( void );
|
||||
void CL_ClearState( void );
|
||||
size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat );
|
||||
|
||||
//
|
||||
// cl_demo.c
|
||||
|
||||
@@ -132,6 +132,8 @@ static struct touch_s
|
||||
int whitetexture;
|
||||
int joytexture; // touch indicator
|
||||
qboolean configchanged;
|
||||
float actual_aspect_ratio; // maximum aspect ratio from launch, or aspect ratio when entering editor
|
||||
float config_aspect_ratio; // aspect ratio set by command from config or after entering editor
|
||||
} touch;
|
||||
|
||||
// private to the engine flags
|
||||
@@ -168,13 +170,42 @@ CVAR_DEFINE_AUTO( touch_emulate, "0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "emulate
|
||||
#define B(x) (button->x)
|
||||
#define SCR_W ((float)refState.width)
|
||||
#define SCR_H ((float)refState.height)
|
||||
#define TO_SCRN_Y(x) (refState.height * (x))
|
||||
#define TO_SCRN_Y(x) (refState.width * (x) * Touch_AspectRatio())
|
||||
#define TO_SCRN_X(x) (refState.width * (x))
|
||||
|
||||
static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 );
|
||||
static void IN_TouchEditClear( void );
|
||||
static void Touch_InitConfig( void );
|
||||
|
||||
void Touch_NotifyResize( void )
|
||||
{
|
||||
if( refState.width && refState.height && ( !touch.configchanged || !touch.actual_aspect_ratio ))
|
||||
{
|
||||
float aspect_ratio = SCR_H/SCR_W;
|
||||
if( aspect_ratio < 0.99 && aspect_ratio > touch.actual_aspect_ratio )
|
||||
touch.actual_aspect_ratio = aspect_ratio;
|
||||
}
|
||||
}
|
||||
|
||||
static inline float Touch_AspectRatio( void )
|
||||
{
|
||||
if( touch.config_aspect_ratio )
|
||||
return touch.config_aspect_ratio;
|
||||
else if( touch.actual_aspect_ratio )
|
||||
return touch.actual_aspect_ratio;
|
||||
else if( refState.width && refState.height )
|
||||
return SCR_H/SCR_W;
|
||||
else
|
||||
return 9.0f / 16.0f;
|
||||
}
|
||||
|
||||
|
||||
static void Touch_ConfigAspectRatio_f( void )
|
||||
{
|
||||
touch.config_aspect_ratio = Q_atof( Cmd_Argv( 1 ));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==========================
|
||||
Touch_ExportButtonToConfig
|
||||
@@ -206,7 +237,7 @@ static inline int Touch_ExportButtonToConfig( file_t *f, touch_button_t *button,
|
||||
|
||||
if( keepAspect )
|
||||
{
|
||||
float aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) );
|
||||
float aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(Touch_AspectRatio()) );
|
||||
FS_Printf( f, " %f\n", aspect );
|
||||
}
|
||||
else FS_Printf( f, "\n" );
|
||||
@@ -271,6 +302,8 @@ qboolean Touch_DumpConfig( const char *name, const char *profilename )
|
||||
FS_Printf( f, "touch_setclientonly 0\n" );
|
||||
FS_Printf( f, "\n// touch buttons\n" );
|
||||
FS_Printf( f, "touch_removeall\n" );
|
||||
FS_Printf( f, "touch_aspectratio %f\n", Touch_AspectRatio());
|
||||
|
||||
|
||||
for( button = touch.list_user.first; button; button = button->next )
|
||||
{
|
||||
@@ -376,7 +409,7 @@ static void Touch_GenerateCode_f( void )
|
||||
if( FBitSet( flags, TOUCH_FL_DEF_HIDE ))
|
||||
SetBits( flags, TOUCH_FL_HIDE );
|
||||
|
||||
aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) );
|
||||
aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(Touch_AspectRatio()) );
|
||||
if( memcmp( &c, &B(color), sizeof( rgba_t ) ) )
|
||||
{
|
||||
Con_Printf( "unsigned char color[] = { %d, %d, %d, %d };\n", B(color[0]), B(color[1]), B(color[2]), B(color[3]) );
|
||||
@@ -549,6 +582,7 @@ static void Touch_RemoveAll_f( void )
|
||||
{
|
||||
IN_TouchEditClear();
|
||||
Touch_ClearList( &touch.list_user );
|
||||
touch.config_aspect_ratio = 0.0f;
|
||||
}
|
||||
|
||||
static void Touch_SetColor( touchbuttonlist_t *list, const char *name, byte *color )
|
||||
@@ -726,6 +760,8 @@ static void Touch_SetCommand_f( void )
|
||||
Con_Printf( S_USAGE "touch_setcommand <name> <command>\n" );
|
||||
}
|
||||
|
||||
static void Touch_LoadDefaults_f( void );
|
||||
|
||||
static void Touch_ReloadConfig_f( void )
|
||||
{
|
||||
touch.state = state_none;
|
||||
@@ -735,8 +771,15 @@ static void Touch_ReloadConfig_f( void )
|
||||
touch.selection->finger = -1;
|
||||
touch.edit = touch.selection = NULL;
|
||||
touch.resize_finger = touch.move_finger = touch.look_finger = touch.wheel_finger = -1;
|
||||
|
||||
Cbuf_AddTextf( "exec %s\n", touch_config_file.string );
|
||||
if( FS_FileExists( touch_config_file.string, true ) )
|
||||
{
|
||||
Cbuf_AddTextf( "exec \"%s\"\n", touch_config_file.string );
|
||||
}
|
||||
else
|
||||
{
|
||||
Touch_LoadDefaults_f();
|
||||
touch.configchanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
static touch_button_t *Touch_AddButton( touchbuttonlist_t *list,
|
||||
@@ -784,7 +827,7 @@ void Touch_AddClientButton( const char *name, const char *texture, const char *c
|
||||
IN_TouchCheckCoords( &x1, &y1, &x2, &y2 );
|
||||
if( round == round_aspect )
|
||||
{
|
||||
y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * aspect;
|
||||
y2 = y1 + ( x2 - x1 ) / (Touch_AspectRatio()) * aspect;
|
||||
}
|
||||
button = Touch_AddButton( &touch.list_user, name, texture, command, x1, y1, x2, y2, color, true );
|
||||
button->flags |= flags | TOUCH_FL_CLIENT | TOUCH_FL_NOEDIT;
|
||||
@@ -809,7 +852,7 @@ static void Touch_LoadDefaults_f( void )
|
||||
if( g_DefaultButtons[i].texturefile[0] == '#' )
|
||||
y2 = y1 + ( (float)clgame.scrInfo.iCharHeight / (float)clgame.scrInfo.iHeight ) * g_DefaultButtons[i].aspect + touch.swidth*2/SCR_H;
|
||||
else
|
||||
y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * g_DefaultButtons[i].aspect;
|
||||
y2 = y1 + (( x2 - x1 ) / Touch_AspectRatio()) * g_DefaultButtons[i].aspect;
|
||||
}
|
||||
|
||||
IN_TouchCheckCoords( &x1, &y1, &x2, &y2 );
|
||||
@@ -817,6 +860,7 @@ static void Touch_LoadDefaults_f( void )
|
||||
button->flags |= g_DefaultButtons[i].flags;
|
||||
button->aspect = g_DefaultButtons[i].aspect;
|
||||
}
|
||||
touch.configchanged = true;
|
||||
}
|
||||
|
||||
// Add default button from client
|
||||
@@ -909,7 +953,7 @@ static void Touch_AddButton_f( void )
|
||||
if( aspect )
|
||||
{
|
||||
if( B( texturefile )[0] != '#' )
|
||||
B( y2 ) = B( y1 ) + ( B( x2 ) - B( x1 )) * ( SCR_W / SCR_H ) * aspect;
|
||||
B( y2 ) = B( y1 ) + (( B( x2 ) - B( x1 )) / Touch_AspectRatio() ) * aspect;
|
||||
B( aspect ) = aspect;
|
||||
}
|
||||
}
|
||||
@@ -917,11 +961,39 @@ static void Touch_AddButton_f( void )
|
||||
|
||||
static void Touch_EnableEdit_f( void )
|
||||
{
|
||||
touch_button_t *button;
|
||||
float current_ratio = SCR_H/SCR_W;
|
||||
if( touch.state == state_none )
|
||||
touch.state = state_edit;
|
||||
touch.resize_finger = touch.move_finger = touch.look_finger = touch.wheel_finger = -1;
|
||||
touch.move_button = NULL;
|
||||
touch.configchanged = true;
|
||||
/* try determine the best ratio
|
||||
* User enters editor. Window now have correct size. Need to fix aspect ratio in some cases */
|
||||
// Case A: no config was loaded, touch was generated with lower height, but window was resized higher, reset it to actual size
|
||||
if( touch.actual_aspect_ratio > current_ratio )
|
||||
touch.actual_aspect_ratio = current_ratio;
|
||||
if( !touch.config_aspect_ratio )
|
||||
touch.config_aspect_ratio = touch.actual_aspect_ratio;
|
||||
// Case B: config was loaded, but window may be resized later, so keep y coordinate as is
|
||||
touch.actual_aspect_ratio = current_ratio;
|
||||
// convert coordinates to actual aspect ratio after it was updated
|
||||
if( touch.config_aspect_ratio != touch.actual_aspect_ratio )
|
||||
{
|
||||
for( button = touch.list_user.first; button; button = button->next )
|
||||
{
|
||||
B(y1) /= touch.actual_aspect_ratio / touch.config_aspect_ratio;
|
||||
B(y2) /= touch.actual_aspect_ratio / touch.config_aspect_ratio;
|
||||
|
||||
// clamp positions to make buttons visible by user
|
||||
if( B(y2) > 1.0f )
|
||||
{
|
||||
B(y1) -= B(y2) - 1.0f;
|
||||
B(y2) -= B(y2) - 1.0f;
|
||||
}
|
||||
}
|
||||
touch.config_aspect_ratio = touch.actual_aspect_ratio;
|
||||
}
|
||||
}
|
||||
|
||||
static void Touch_DisableEdit_f( void )
|
||||
@@ -956,7 +1028,7 @@ static void Touch_DeleteProfile_f( void )
|
||||
|
||||
static void Touch_InitEditor( void )
|
||||
{
|
||||
float x = 0.1f * (SCR_H/SCR_W);
|
||||
float x = 0.1f * (Touch_AspectRatio());
|
||||
float y = 0.05f;
|
||||
touch_button_t *temp;
|
||||
rgba_t color;
|
||||
@@ -1051,6 +1123,7 @@ void Touch_Init( void )
|
||||
Cmd_AddRestrictedCommand( "touch_generate_code", Touch_GenerateCode_f, "create code sample for mobility API" );
|
||||
Cmd_AddCommand( "touch_fade", Touch_Fade_f, "start fade animation for selected buttons" );
|
||||
Cmd_AddRestrictedCommand( "touch_toggleselection", Touch_ToggleSelection_f, "toggle vidibility on selected button in editor" );
|
||||
Cmd_AddRestrictedCommand( "touch_aspectratio", Touch_ConfigAspectRatio_f, "set current aspect ratio" );
|
||||
|
||||
// not saved, just runtime state for scripting
|
||||
Cvar_RegisterVariable( &touch_in_menu );
|
||||
@@ -1087,7 +1160,7 @@ void Touch_Init( void )
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 10 )
|
||||
SDL_SetHint( SDL_HINT_MOUSE_TOUCH_EVENTS, "0" );
|
||||
SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" );
|
||||
#else
|
||||
#elif defined(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH)
|
||||
SDL_SetHint( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1" );
|
||||
#endif
|
||||
|
||||
@@ -1170,9 +1243,9 @@ static void Touch_DrawTexture ( float x1, float y1, float x2, float y2, int text
|
||||
}
|
||||
|
||||
#define GRID_COUNT_X ((int)touch_grid_count.value)
|
||||
#define GRID_COUNT_Y (((int)touch_grid_count.value) * SCR_H / SCR_W)
|
||||
#define GRID_COUNT_Y (((int)touch_grid_count.value) * Touch_AspectRatio())
|
||||
#define GRID_X (1.0f/GRID_COUNT_X)
|
||||
#define GRID_Y (SCR_W/SCR_H/GRID_COUNT_X)
|
||||
#define GRID_Y (1.0f/Touch_AspectRatio()/GRID_COUNT_X)
|
||||
#define GRID_ROUND_X(x) ((float)round( x * GRID_COUNT_X ) / GRID_COUNT_X)
|
||||
#define GRID_ROUND_Y(x) ((float)round( x * GRID_COUNT_Y ) / GRID_COUNT_Y)
|
||||
|
||||
@@ -1250,7 +1323,7 @@ static float Touch_DrawText( float x1, float y1, float x2, float y2, const char
|
||||
{
|
||||
while( *s && ( *s != '\n' ) && ( *s != ';' ) && ( x1 < maxx ) )
|
||||
x1 += Touch_DrawCharacter( x1, y1, *s++, size );
|
||||
y1 += cls.creditsFont.charHeight / 1024.f * size / SCR_H * SCR_W;
|
||||
y1 += cls.creditsFont.charHeight / 1024.f * size / Touch_AspectRatio();
|
||||
|
||||
if( y1 >= maxy )
|
||||
break;
|
||||
@@ -1357,11 +1430,12 @@ void Touch_Draw( void )
|
||||
if( !touch.initialized || ( !touch_enable.value && !touch.clientonly ))
|
||||
return;
|
||||
|
||||
Touch_InitConfig();
|
||||
|
||||
if( cls.key_dest != key_game && !touch_in_menu.value )
|
||||
return;
|
||||
|
||||
Touch_InitConfig();
|
||||
|
||||
|
||||
ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture );
|
||||
|
||||
if( touch.state >= state_edit && touch_grid_enable.value )
|
||||
@@ -1948,6 +2022,8 @@ static int Touch_ControlsEvent( touchEventType type, int fingerID, float x, floa
|
||||
|
||||
int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy )
|
||||
{
|
||||
y *= SCR_H/SCR_W/Touch_AspectRatio();
|
||||
// Con_Printf("%f %f\n", TO_SCRN_X(x), TO_SCRN_Y(y));
|
||||
// simulate menu mouse click
|
||||
if( cls.key_dest != key_game && !touch_in_menu.value )
|
||||
{
|
||||
|
||||
@@ -172,6 +172,8 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
|
||||
{
|
||||
if( newstate == oldstate )
|
||||
return;
|
||||
if( m_ignore.value )
|
||||
return;
|
||||
|
||||
// since SetCursorType controls cursor visibility
|
||||
// execute it first, and then check mouse grab state
|
||||
@@ -212,6 +214,9 @@ void IN_CheckMouseState( qboolean active )
|
||||
qboolean useRawInput = true; // always use SDL code
|
||||
#endif
|
||||
|
||||
if( m_ignore.value )
|
||||
return;
|
||||
|
||||
if( active && useRawInput && !host.mouse_visible && cls.state == ca_active )
|
||||
{
|
||||
if( !s_bRawInput )
|
||||
|
||||
@@ -75,6 +75,7 @@ void Touch_ResetDefaultButtons( void );
|
||||
int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy );
|
||||
void Touch_KeyEvent( int key, int down );
|
||||
qboolean Touch_WantVisibleCursor( void );
|
||||
void Touch_NotifyResize( void );
|
||||
|
||||
//
|
||||
// in_joy.c
|
||||
|
||||
@@ -1025,12 +1025,21 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
host.rootdir[0] = 0;
|
||||
}
|
||||
#elif (XASH_SDL == 2) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2
|
||||
char *szBasePath;
|
||||
|
||||
if( !( szBasePath = SDL_GetBasePath() ) )
|
||||
char *szBasePath = SDL_GetBasePath();
|
||||
if( szBasePath )
|
||||
{
|
||||
Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir ));
|
||||
SDL_free( szBasePath );
|
||||
}
|
||||
else
|
||||
{
|
||||
#if XASH_POSIX || XASH_WIN32
|
||||
if( !getcwd( host.rootdir, sizeof( host.rootdir )))
|
||||
Sys_Error( "couldn't determine current directory: %s, getcwd: %s", SDL_GetError(), strerror( errno ));
|
||||
#else
|
||||
Sys_Error( "couldn't determine current directory: %s", SDL_GetError() );
|
||||
Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir ));
|
||||
SDL_free( szBasePath );
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if( !getcwd( host.rootdir, sizeof( host.rootdir )))
|
||||
{
|
||||
|
||||
@@ -142,6 +142,7 @@ void Image_CopyPalette32bit( void );
|
||||
void Image_SetPixelFormat( void );
|
||||
void Image_GetPaletteQ1( void );
|
||||
void Image_GetPaletteHL( void );
|
||||
size_t Image_ComputeSize( int type, int width, int height, int depth );
|
||||
|
||||
//
|
||||
// formats load
|
||||
@@ -156,6 +157,7 @@ qboolean Image_LoadDDS( const char *name, const byte *buffer, fs_offset_t filesi
|
||||
qboolean Image_LoadFNT( const char *name, const byte *buffer, fs_offset_t filesize );
|
||||
qboolean Image_LoadLMP( const char *name, const byte *buffer, fs_offset_t filesize );
|
||||
qboolean Image_LoadPAL( const char *name, const byte *buffer, fs_offset_t filesize );
|
||||
qboolean Image_LoadKTX2( const char *name, const byte *buffer, fs_offset_t filesize );
|
||||
|
||||
//
|
||||
// formats save
|
||||
|
||||
@@ -104,6 +104,13 @@ void Image_DXTGetPixelFormat( dds_t *hdr, dds_header_dxt10_t *headerExt )
|
||||
{
|
||||
switch( headerExt->dxgiFormat )
|
||||
{
|
||||
case DXGI_FORMAT_BC4_TYPELESS:
|
||||
case DXGI_FORMAT_BC4_UNORM:
|
||||
image.type = PF_BC4_UNSIGNED;
|
||||
break;
|
||||
case DXGI_FORMAT_BC4_SNORM:
|
||||
image.type = PF_BC4_SIGNED;
|
||||
break;
|
||||
case DXGI_FORMAT_BC6H_SF16:
|
||||
image.type = PF_BC6H_SIGNED;
|
||||
break;
|
||||
@@ -112,9 +119,20 @@ void Image_DXTGetPixelFormat( dds_t *hdr, dds_header_dxt10_t *headerExt )
|
||||
image.type = PF_BC6H_UNSIGNED;
|
||||
break;
|
||||
case DXGI_FORMAT_BC7_UNORM:
|
||||
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||
case DXGI_FORMAT_BC7_TYPELESS:
|
||||
image.type = PF_BC7;
|
||||
image.type = PF_BC7_UNORM;
|
||||
break;
|
||||
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||
image.type = PF_BC7_SRGB;
|
||||
break;
|
||||
case DXGI_FORMAT_BC5_TYPELESS:
|
||||
image.type = PF_ATI2;
|
||||
break;
|
||||
case DXGI_FORMAT_BC5_UNORM:
|
||||
image.type = PF_BC5_UNSIGNED;
|
||||
break;
|
||||
case DXGI_FORMAT_BC5_SNORM:
|
||||
image.type = PF_BC5_SIGNED;
|
||||
break;
|
||||
default:
|
||||
image.type = PF_UNKNOWN;
|
||||
@@ -122,7 +140,7 @@ void Image_DXTGetPixelFormat( dds_t *hdr, dds_header_dxt10_t *headerExt )
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
switch( hdr->dsPixelFormat.dwFourCC )
|
||||
{
|
||||
case TYPE_DXT1:
|
||||
@@ -143,6 +161,15 @@ void Image_DXTGetPixelFormat( dds_t *hdr, dds_header_dxt10_t *headerExt )
|
||||
case TYPE_ATI2:
|
||||
image.type = PF_ATI2;
|
||||
break;
|
||||
case TYPE_BC5S:
|
||||
image.type = PF_BC5_SIGNED;
|
||||
break;
|
||||
case TYPE_BC4S:
|
||||
image.type = PF_BC4_SIGNED;
|
||||
break;
|
||||
case TYPE_BC4U:
|
||||
image.type = PF_BC4_UNSIGNED;
|
||||
break;
|
||||
default:
|
||||
image.type = PF_UNKNOWN; // assume error
|
||||
break;
|
||||
@@ -188,27 +215,6 @@ void Image_DXTGetPixelFormat( dds_t *hdr, dds_header_dxt10_t *headerExt )
|
||||
image.num_mips = hdr->dwMipMapCount; // get actual mip count
|
||||
}
|
||||
|
||||
size_t Image_DXTGetLinearSize( int type, int width, int height, int depth )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case PF_DXT1: return ((( width + 3 ) / 4 ) * (( height + 3 ) / 4 ) * depth * 8 );
|
||||
case PF_DXT3:
|
||||
case PF_DXT5:
|
||||
case PF_BC6H_SIGNED:
|
||||
case PF_BC6H_UNSIGNED:
|
||||
case PF_BC7:
|
||||
case PF_ATI2: return ((( width + 3 ) / 4 ) * (( height + 3 ) / 4 ) * depth * 16 );
|
||||
case PF_LUMINANCE: return (width * height * depth);
|
||||
case PF_BGR_24:
|
||||
case PF_RGB_24: return (width * height * depth * 3);
|
||||
case PF_BGRA_32:
|
||||
case PF_RGBA_32: return (width * height * depth * 4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t Image_DXTCalcMipmapSize( dds_t *hdr )
|
||||
{
|
||||
size_t buffsize = 0;
|
||||
@@ -219,7 +225,7 @@ size_t Image_DXTCalcMipmapSize( dds_t *hdr )
|
||||
{
|
||||
width = Q_max( 1, ( hdr->dwWidth >> i ));
|
||||
height = Q_max( 1, ( hdr->dwHeight >> i ));
|
||||
buffsize += Image_DXTGetLinearSize( image.type, width, height, image.depth );
|
||||
buffsize += Image_ComputeSize( image.type, width, height, image.depth );
|
||||
}
|
||||
|
||||
return buffsize;
|
||||
@@ -255,7 +261,7 @@ uint Image_DXTCalcSize( const char *name, dds_t *hdr, size_t filesize )
|
||||
|
||||
if( filesize != buffsize ) // main check
|
||||
{
|
||||
Con_DPrintf( S_WARN "Image_LoadDDS: (%s) probably corrupted (%i should be %lu)\n", name, buffsize, filesize );
|
||||
Con_DPrintf( S_WARN "Image_LoadDDS: (%s) probably corrupted (%zu should be %lu)\n", name, buffsize, filesize );
|
||||
if( buffsize > filesize )
|
||||
return false;
|
||||
}
|
||||
@@ -268,7 +274,7 @@ void Image_DXTAdjustVolume( dds_t *hdr )
|
||||
if( hdr->dwDepth <= 1 )
|
||||
return;
|
||||
|
||||
hdr->dwLinearSize = Image_DXTGetLinearSize( image.type, hdr->dwWidth, hdr->dwHeight, hdr->dwDepth );
|
||||
hdr->dwLinearSize = Image_ComputeSize( image.type, hdr->dwWidth, hdr->dwHeight, hdr->dwDepth );
|
||||
hdr->dwFlags |= DDS_LINEARSIZE;
|
||||
}
|
||||
|
||||
@@ -323,7 +329,7 @@ qboolean Image_LoadDDS( const char *name, const byte *buffer, fs_offset_t filesi
|
||||
Image_DXTGetPixelFormat( &header, &header2 ); // and image type too :)
|
||||
Image_DXTAdjustVolume( &header );
|
||||
|
||||
if( !Image_CheckFlag( IL_DDS_HARDWARE ) && ImageDXT( image.type ))
|
||||
if( !Image_CheckFlag( IL_DDS_HARDWARE ) && ImageCompressed( image.type ))
|
||||
return false; // silently rejected
|
||||
|
||||
if( image.type == PF_UNKNOWN )
|
||||
@@ -356,8 +362,10 @@ qboolean Image_LoadDDS( const char *name, const byte *buffer, fs_offset_t filesi
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
else if( image.type == PF_DXT5 && Image_CheckDXT5Alpha( &header, fin ))
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
else if ( image.type == PF_BC7 )
|
||||
SetBits(image.flags, IMAGE_HAS_ALPHA);
|
||||
else if( image.type == PF_BC5_SIGNED || image.type == PF_BC5_UNSIGNED )
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
else if( image.type == PF_BC7_UNORM || image.type == PF_BC7_SRGB )
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
if( !FBitSet( header.dsPixelFormat.dwFlags, DDS_LUMINANCE ))
|
||||
SetBits( image.flags, IMAGE_HAS_COLOR );
|
||||
break;
|
||||
|
||||
@@ -32,6 +32,9 @@ GNU General Public License for more details.
|
||||
#define TYPE_DX10 (('0'<<24)+('1'<<16)+('X'<<8)+'D') // little-endian "DX10"
|
||||
#define TYPE_ATI1 (('1'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI1"
|
||||
#define TYPE_ATI2 (('2'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI2"
|
||||
#define TYPE_BC5S (('S'<<24)+('5'<<16)+('C'<<8)+'B') // little-endian "BC5S"
|
||||
#define TYPE_BC4S (('S'<<24)+('4'<<16)+('C'<<8)+'B') // little-endian "BC4S"
|
||||
#define TYPE_BC4U (('U'<<24)+('4'<<16)+('C'<<8)+'B') // little-endian "BC4U"
|
||||
#define TYPE_RXGB (('B'<<24)+('G'<<16)+('X'<<8)+'R') // little-endian "RXGB" doom3 normalmaps
|
||||
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
|
||||
#define TYPE_o (('\0'<<24)+('\0'<<16)+('\0'<<8)+'o') // little-endian "o"
|
||||
@@ -202,7 +205,7 @@ typedef enum
|
||||
DXGI_FORMAT_FORCE_UINT = 0xffffffff
|
||||
} dxgi_format_t;
|
||||
|
||||
typedef enum
|
||||
typedef enum
|
||||
{
|
||||
D3D10_RESOURCE_DIMENSION_UNKNOWN = 0,
|
||||
D3D10_RESOURCE_DIMENSION_BUFFER = 1,
|
||||
|
||||
204
engine/common/imagelib/img_ktx2.c
Normal file
204
engine/common/imagelib/img_ktx2.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
img_ktx2.c - ktx2 format load
|
||||
Copyright (C) 2023 Provod
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "imagelib.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
#include "img_ktx2.h"
|
||||
|
||||
static void Image_KTX2Format( uint32_t ktx2_format )
|
||||
{
|
||||
switch( ktx2_format )
|
||||
{
|
||||
case KTX2_FORMAT_BC4_UNORM_BLOCK:
|
||||
image.type = PF_BC4_UNSIGNED;
|
||||
// 1 component for ref_gl
|
||||
break;
|
||||
case KTX2_FORMAT_BC4_SNORM_BLOCK:
|
||||
image.type = PF_BC4_SIGNED;
|
||||
// 1 component for ref_gl
|
||||
break;
|
||||
case KTX2_FORMAT_BC5_UNORM_BLOCK:
|
||||
image.type = PF_BC5_UNSIGNED;
|
||||
// 2 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
break;
|
||||
case KTX2_FORMAT_BC5_SNORM_BLOCK:
|
||||
image.type = PF_BC5_SIGNED;
|
||||
// 2 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_ALPHA );
|
||||
break;
|
||||
case KTX2_FORMAT_BC6H_UFLOAT_BLOCK:
|
||||
image.type = PF_BC6H_UNSIGNED;
|
||||
// 3 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_COLOR );
|
||||
break;
|
||||
case KTX2_FORMAT_BC6H_SFLOAT_BLOCK:
|
||||
image.type = PF_BC6H_SIGNED;
|
||||
// 3 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_COLOR );
|
||||
break;
|
||||
case KTX2_FORMAT_BC7_UNORM_BLOCK:
|
||||
image.type = PF_BC7_UNORM;
|
||||
// 4 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );
|
||||
break;
|
||||
case KTX2_FORMAT_BC7_SRGB_BLOCK:
|
||||
image.type = PF_BC7_SRGB;
|
||||
// 4 components for ref_gl
|
||||
SetBits( image.flags, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );
|
||||
break;
|
||||
default:
|
||||
image.type = PF_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static qboolean Image_KTX2Parse( const ktx2_header_t *header, const byte *buffer, fs_offset_t filesize )
|
||||
{
|
||||
ktx2_index_t index;
|
||||
size_t total_size = 0;
|
||||
size_t max_offset = 0;
|
||||
const byte *const levels_begin = buffer + KTX2_LEVELS_OFFSET;
|
||||
|
||||
// Sets image.type and image.flags
|
||||
Image_KTX2Format( header->vkFormat );
|
||||
|
||||
if( image.type == PF_UNKNOWN )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: unsupported KTX2 format %d\n", __FUNCTION__, header->vkFormat );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Image_CheckFlag( IL_DDS_HARDWARE ) && ImageCompressed( image.type ))
|
||||
{
|
||||
Con_DPrintf( S_WARN "%s: has compressed format, but support is not advertized\n", __FUNCTION__ );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( header->pixelDepth > 1 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: unsupported KTX2 pixelDepth %d\n", __FUNCTION__, header->pixelDepth );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( header->faceCount > 1 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: unsupported KTX2 faceCount %d\n", __FUNCTION__, header->faceCount );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( header->layerCount > 1 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: unsupported KTX2 layerCount %d\n", __FUNCTION__, header->layerCount );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( header->supercompressionScheme != 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: unsupported KTX2 supercompressionScheme %d\n", __FUNCTION__, header->supercompressionScheme );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( header->levelCount * sizeof( ktx2_level_t ) + KTX2_LEVELS_OFFSET > filesize )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: file abruptly ends\n", __FUNCTION__ );
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy( &index, buffer + KTX2_IDENTIFIER_SIZE + sizeof( ktx2_header_t ), sizeof( index ));
|
||||
|
||||
for( int mip = 0; mip < header->levelCount; ++mip )
|
||||
{
|
||||
const uint32_t width = Q_max( 1, ( header->pixelWidth >> mip ));
|
||||
const uint32_t height = Q_max( 1, ( header->pixelHeight >> mip ));
|
||||
const uint32_t mip_size = Image_ComputeSize( image.type, width, height, image.depth );
|
||||
|
||||
ktx2_level_t level;
|
||||
memcpy( &level, levels_begin + mip * sizeof( level ), sizeof( level ));
|
||||
|
||||
if( mip_size != level.byteLength )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: mip=%d size mismatch read=%d, but computed=%d\n",
|
||||
__FUNCTION__, mip, (int)level.byteLength, mip_size );
|
||||
return false;
|
||||
}
|
||||
|
||||
total_size += level.byteLength;
|
||||
max_offset = Q_max( max_offset, level.byteLength + level.byteOffset );
|
||||
}
|
||||
|
||||
if( max_offset > filesize )
|
||||
return false;
|
||||
|
||||
image.size = total_size;
|
||||
image.num_mips = header->levelCount;
|
||||
|
||||
image.rgba = Mem_Malloc( host.imagepool, image.size );
|
||||
memcpy( image.rgba, buffer, image.size );
|
||||
|
||||
for( int mip = 0, cursor = 0; mip < header->levelCount; ++mip )
|
||||
{
|
||||
ktx2_level_t level;
|
||||
memcpy( &level, levels_begin + mip * sizeof( level ), sizeof( level ));
|
||||
memcpy( image.rgba + cursor, buffer + level.byteOffset, level.byteLength );
|
||||
cursor += level.byteLength;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
qboolean Image_LoadKTX2( const char *name, const byte *buffer, fs_offset_t filesize )
|
||||
{
|
||||
ktx2_header_t header;
|
||||
|
||||
if( filesize < KTX2_MINIMAL_HEADER_SIZE )
|
||||
return false;
|
||||
|
||||
if( memcmp( buffer, KTX2_IDENTIFIER, KTX2_IDENTIFIER_SIZE ) != 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: (%s) has invalid identifier\n", __FUNCTION__, name );
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy( &header, buffer + KTX2_IDENTIFIER_SIZE, sizeof( header ));
|
||||
|
||||
image.width = header.pixelWidth;
|
||||
image.height = header.pixelHeight;
|
||||
image.depth = Q_max( 1, header.pixelDepth );
|
||||
image.num_mips = 1;
|
||||
|
||||
ClearBits( image.flags, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA | IMAGE_HAS_LUMA );
|
||||
|
||||
if( !Image_KTX2Parse( &header, buffer, filesize ))
|
||||
{
|
||||
if( !Image_CheckFlag( IL_KTX2_RAW ))
|
||||
return false;
|
||||
|
||||
// If KTX2 to imagelib conversion failed, try passing the file as raw data.
|
||||
// This is useful for ref_vk which can directly support hundreds of formats which we don't convert to pixformat_t here
|
||||
|
||||
Con_DPrintf( S_WARN "%s: (%s) could not be converted to supported imagelib format, passing as raw KTX2 data\n", __FUNCTION__, name );
|
||||
// This is a catch-all for ref_vk, which can do this format directly and natively
|
||||
image.type = PF_KTX2_RAW;
|
||||
|
||||
image.size = filesize;
|
||||
//image.encode = TODO custom encode type?
|
||||
|
||||
image.rgba = Mem_Malloc( host.imagepool, image.size );
|
||||
memcpy( image.rgba, buffer, image.size );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
79
engine/common/imagelib/img_ktx2.h
Normal file
79
engine/common/imagelib/img_ktx2.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
img_ktx2.h - ktx2 format reference
|
||||
Copyright (C) 2023 Provod
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
#ifndef IMG_KTX2_H
|
||||
#define IMG_KTX2_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define KTX2_IDENTIFIER_SIZE 12
|
||||
#define KTX2_IDENTIFIER "\xABKTX 20\xBB\r\n\x1A\n"
|
||||
|
||||
/*
|
||||
static const char k_ktx2_identifier[KTX2_IDENTIFIER_SIZE] =
|
||||
{
|
||||
'\xAB', 'K', 'T', 'X', ' ', '2', '0', '\xBB', '\r', '\n', '\x1A', '\n'
|
||||
};
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t vkFormat;
|
||||
uint32_t typeSize;
|
||||
uint32_t pixelWidth;
|
||||
uint32_t pixelHeight;
|
||||
uint32_t pixelDepth;
|
||||
uint32_t layerCount;
|
||||
uint32_t faceCount;
|
||||
uint32_t levelCount;
|
||||
uint32_t supercompressionScheme;
|
||||
} ktx2_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dfdByteOffset;
|
||||
uint32_t dfdByteLength;
|
||||
uint32_t kvdByteOffset;
|
||||
uint32_t kvdByteLength;
|
||||
uint64_t sgdByteOffset;
|
||||
uint64_t sgdByteLength;
|
||||
} ktx2_index_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t byteOffset;
|
||||
uint64_t byteLength;
|
||||
uint64_t uncompressedByteLength;
|
||||
} ktx2_level_t;
|
||||
|
||||
#define KTX2_LEVELS_OFFSET ( KTX2_IDENTIFIER_SIZE + sizeof( ktx2_header_t ) + sizeof( ktx2_index_t ))
|
||||
|
||||
#define KTX2_MINIMAL_HEADER_SIZE ( KTX2_LEVELS_OFFSET + sizeof( ktx2_level_t ))
|
||||
|
||||
// These have the same values as enum VkFormat in vulkan_core.h
|
||||
// There are hundreds of formats which can be contained in KTX2.
|
||||
// Below are listed the ones which are supported here. This list can be extended.
|
||||
typedef enum
|
||||
{
|
||||
KTX2_FORMAT_BC4_UNORM_BLOCK = 139,
|
||||
KTX2_FORMAT_BC4_SNORM_BLOCK = 140,
|
||||
KTX2_FORMAT_BC5_UNORM_BLOCK = 141,
|
||||
KTX2_FORMAT_BC5_SNORM_BLOCK = 142,
|
||||
KTX2_FORMAT_BC6H_UFLOAT_BLOCK = 143,
|
||||
KTX2_FORMAT_BC6H_SFLOAT_BLOCK = 144,
|
||||
KTX2_FORMAT_BC7_UNORM_BLOCK = 145,
|
||||
KTX2_FORMAT_BC7_SRGB_BLOCK = 146,
|
||||
} ktx2_format_t;
|
||||
|
||||
#endif // IMG_KTX2_H
|
||||
@@ -105,6 +105,7 @@ static const loadpixformat_t load_game[] =
|
||||
{ "%s%s.%s", "lmp", Image_LoadLMP, IL_HINT_NO }, // hl menu images (cached.wad etc)
|
||||
{ "%s%s.%s", "fnt", Image_LoadFNT, IL_HINT_HL }, // hl console font (fonts.wad etc)
|
||||
{ "%s%s.%s", "pal", Image_LoadPAL, IL_HINT_NO }, // install studio\sprite palette
|
||||
{ "%s%s.%s", "ktx2", Image_LoadKTX2, IL_HINT_NO }, // ktx2 for world and studio models
|
||||
{ NULL, NULL, NULL, IL_HINT_NO }
|
||||
};
|
||||
|
||||
@@ -283,8 +284,10 @@ int Image_ComparePalette( const byte *pal )
|
||||
void Image_SetPalette( const byte *pal, uint *d_table )
|
||||
{
|
||||
byte rgba[4];
|
||||
uint uirgba; // TODO: palette looks byte-swapped on big-endian
|
||||
int i;
|
||||
|
||||
|
||||
// setup palette
|
||||
switch( image.d_rendermode )
|
||||
{
|
||||
@@ -295,7 +298,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
|
||||
rgba[1] = pal[i*3+1];
|
||||
rgba[2] = pal[i*3+2];
|
||||
rgba[3] = 0xFF;
|
||||
d_table[i] = *(uint *)rgba;
|
||||
memcpy( &uirgba, rgba, sizeof( uirgba ));
|
||||
d_table[i] = uirgba;
|
||||
}
|
||||
break;
|
||||
case LUMP_GRADIENT:
|
||||
@@ -305,7 +309,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
|
||||
rgba[1] = pal[766];
|
||||
rgba[2] = pal[767];
|
||||
rgba[3] = i;
|
||||
d_table[i] = *(uint *)rgba;
|
||||
memcpy( &uirgba, rgba, sizeof( uirgba ));
|
||||
d_table[i] = uirgba;
|
||||
}
|
||||
break;
|
||||
case LUMP_MASKED:
|
||||
@@ -315,7 +320,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
|
||||
rgba[1] = pal[i*3+1];
|
||||
rgba[2] = pal[i*3+2];
|
||||
rgba[3] = 0xFF;
|
||||
d_table[i] = *(uint *)rgba;
|
||||
memcpy( &uirgba, rgba, sizeof( uirgba ));
|
||||
d_table[i] = uirgba;
|
||||
}
|
||||
d_table[255] = 0;
|
||||
break;
|
||||
@@ -326,7 +332,8 @@ void Image_SetPalette( const byte *pal, uint *d_table )
|
||||
rgba[1] = pal[i*4+1];
|
||||
rgba[2] = pal[i*4+2];
|
||||
rgba[3] = pal[i*4+3];
|
||||
d_table[i] = *(uint *)rgba;
|
||||
memcpy( &uirgba, rgba, sizeof( uirgba ));
|
||||
d_table[i] = uirgba;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1446,3 +1453,36 @@ qboolean Image_Process(rgbdata_t **pix, int width, int height, uint flags, float
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// This codebase has too many copies of this function:
|
||||
// - ref_gl has one
|
||||
// - ref_vk has one
|
||||
// - ref_soft has one
|
||||
// - many more places probably have one too
|
||||
// TODO figure out how to make it available for ref_*
|
||||
size_t Image_ComputeSize( int type, int width, int height, int depth )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case PF_DXT1:
|
||||
case PF_BC4_SIGNED:
|
||||
case PF_BC4_UNSIGNED:
|
||||
return ((( width + 3 ) / 4 ) * (( height + 3 ) / 4 ) * depth * 8 );
|
||||
case PF_DXT3:
|
||||
case PF_DXT5:
|
||||
case PF_ATI2:
|
||||
case PF_BC5_UNSIGNED:
|
||||
case PF_BC5_SIGNED:
|
||||
case PF_BC6H_SIGNED:
|
||||
case PF_BC6H_UNSIGNED:
|
||||
case PF_BC7_UNORM:
|
||||
case PF_BC7_SRGB: return ((( width + 3 ) / 4 ) * (( height + 3 ) / 4 ) * depth * 16 );
|
||||
case PF_LUMINANCE: return ( width * height * depth );
|
||||
case PF_BGR_24:
|
||||
case PF_RGB_24: return ( width * height * depth * 3 );
|
||||
case PF_BGRA_32:
|
||||
case PF_RGBA_32: return ( width * height * depth * 4 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -419,5 +419,6 @@ void NET_InitMasters( void )
|
||||
|
||||
// keep main master always there
|
||||
NET_AddMaster( MASTERSERVER_ADR, false );
|
||||
NET_AddMaster( MASTERSERVER_ADR_TEST, false );
|
||||
NET_LoadMasters( );
|
||||
}
|
||||
|
||||
@@ -274,8 +274,8 @@ static void NET_NetadrToSockadr( netadr_t *a, struct sockaddr_storage *s )
|
||||
else if( a->type == NA_IP )
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = *(uint32_t *)&a->ip;
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = a->ip4;
|
||||
}
|
||||
else if( a->type6 == NA_IP6 )
|
||||
{
|
||||
@@ -314,7 +314,7 @@ static void NET_SockadrToNetadr( const struct sockaddr_storage *s, netadr_t *a )
|
||||
if( s->ss_family == AF_INET )
|
||||
{
|
||||
a->type = NA_IP;
|
||||
*(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
|
||||
a->ip4 = ((struct sockaddr_in *)s)->sin_addr.s_addr;
|
||||
a->port = ((struct sockaddr_in *)s)->sin_port;
|
||||
}
|
||||
else if( s->ss_family == AF_INET6 )
|
||||
|
||||
@@ -70,6 +70,7 @@ GNU General Public License for more details.
|
||||
#define NET_MAX_MESSAGE PAD_NUMBER(( NET_MAX_PAYLOAD + HEADER_BYTES ), 16 )
|
||||
|
||||
#define MASTERSERVER_ADR "mentality.rip:27010"
|
||||
#define MASTERSERVER_ADR_TEST "mentality.rip:27011"
|
||||
#define MS_SCAN_REQUEST "1\xFF" "0.0.0.0:0\0"
|
||||
|
||||
#define PORT_MASTER 27010
|
||||
|
||||
@@ -149,7 +149,7 @@ void Sys_InitLog( void )
|
||||
s_ld.logfileno = fileno( s_ld.logfile );
|
||||
|
||||
fprintf( s_ld.logfile, "=================================================================================\n" );
|
||||
fprintf( s_ld.logfile, "\t%s (build %i) started at %s\n", s_ld.title, Q_buildnum(), Q_timestamp( TIME_FULL ) );
|
||||
fprintf( s_ld.logfile, "\t%s (build %i commit %s (%s-%s)) started at %s\n", s_ld.title, Q_buildnum(), Q_buildcommit(), Q_buildos(), Q_buildarch(), Q_timestamp( TIME_FULL ) );
|
||||
fprintf( s_ld.logfile, "=================================================================================\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,6 +438,25 @@ GL_GetProcAddress
|
||||
void *GL_GetProcAddress( const char *name )
|
||||
{
|
||||
void *func = SDL_GL_GetProcAddress( name );
|
||||
#if !SDL_VERSION_ATLEAST( 2, 0, 6 ) && XASH_POSIX
|
||||
if( !func && Sys_CheckParm( "-egl" ))
|
||||
{
|
||||
/*
|
||||
* SDL2 has broken SDL_GL_GetProcAddress until this commit if using egl:
|
||||
* https://github.com/libsdl-org/SDL/commit/466ba57d42d244e80357e9ad3011c50af30ed225
|
||||
* so call eglGetProcAddress directly
|
||||
* */
|
||||
static void *(*peglGetProcAddress)( const char * );
|
||||
if( !peglGetProcAddress )
|
||||
{
|
||||
void *lib = dlopen( "libEGL.so", RTLD_NOW );
|
||||
if( lib )
|
||||
*(void**)&peglGetProcAddress = dlsym( lib, "eglGetProcAddress" );
|
||||
}
|
||||
if( peglGetProcAddress )
|
||||
func = peglGetProcAddress( name );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if XASH_PSVITA
|
||||
// try to find in main module
|
||||
@@ -626,9 +645,9 @@ void VID_RestoreScreenResolution( void )
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
static void VID_SetWindowIcon( SDL_Window *hWnd )
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
rgbdata_t *icon = NULL;
|
||||
char iconpath[MAX_STRING];
|
||||
const char *localIcoPath;
|
||||
@@ -666,8 +685,8 @@ static void VID_SetWindowIcon( SDL_Window *hWnd )
|
||||
#if XASH_WIN32 // ICO support only for Win32
|
||||
WIN_SetWindowIcon( LoadIcon( host.hInst, MAKEINTRESOURCE( 101 )));
|
||||
#endif
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
}
|
||||
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||
|
||||
static qboolean VID_CreateWindowWithSafeGL( const char *wndname, int xpos, int ypos, int w, int h, uint32_t flags )
|
||||
{
|
||||
@@ -785,6 +804,7 @@ qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode )
|
||||
else VID_RestoreScreenResolution();
|
||||
#endif
|
||||
|
||||
VID_SetWindowIcon( host.hWnd );
|
||||
SDL_ShowWindow( host.hWnd );
|
||||
|
||||
if( glw_state.software )
|
||||
@@ -996,8 +1016,12 @@ qboolean R_Init_Video( const int type )
|
||||
refState.desktopBitsPixel = 16;
|
||||
#endif
|
||||
|
||||
#ifdef SDL_HINT_QTWAYLAND_WINDOW_FLAGS
|
||||
SDL_SetHint( SDL_HINT_QTWAYLAND_WINDOW_FLAGS, "OverridesSystemGestures" );
|
||||
#endif
|
||||
#ifdef SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION
|
||||
SDL_SetHint( SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION, "landscape" );
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST( 2, 0, 0 ) && !XASH_WIN32
|
||||
SDL_SetHint( "SDL_VIDEO_X11_XRANDR", "1" );
|
||||
|
||||
@@ -121,8 +121,10 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg )
|
||||
{
|
||||
value = MSG_ReadUBitLong( msg, 32 );
|
||||
|
||||
LittleLongSW( value );
|
||||
|
||||
// will be compare only first 4 bytes
|
||||
if( value != *(int *)r->rgucMD5_hash )
|
||||
if( memcmp( &value, r->rgucMD5_hash, 4 ))
|
||||
badresindex = idx + 1;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -166,7 +166,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex )
|
||||
}
|
||||
else if( FBitSet( tex->flags, TF_NOMIPMAP ) || tex->numMips <= 1 )
|
||||
{
|
||||
if( FBitSet( tex->flags, TF_NEAREST ) || ( IsLightMap( tex ) && gl_lightmap_nearest.value ))
|
||||
if( FBitSet( tex->flags, TF_NEAREST ) || ( IsLightMap( tex ) && gl_lightmap_nearest.value ) || ( tex->flags == TF_SKYSIDE && gl_texture_nearest.value ))
|
||||
{
|
||||
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
@@ -388,7 +388,8 @@ static size_t GL_CalcImageSize( pixformat_t format, int width, int height, int d
|
||||
case PF_DXT5:
|
||||
case PF_BC6H_SIGNED:
|
||||
case PF_BC6H_UNSIGNED:
|
||||
case PF_BC7:
|
||||
case PF_BC7_UNORM:
|
||||
case PF_BC7_SRGB:
|
||||
case PF_ATI2:
|
||||
size = (((width + 3) >> 2) * ((height + 3) >> 2) * 16) * depth;
|
||||
break;
|
||||
@@ -694,7 +695,7 @@ static void GL_SetTextureFormat( gl_texture_t *tex, pixformat_t format, int chan
|
||||
|
||||
Assert( tex != NULL );
|
||||
|
||||
if( ImageDXT( format ))
|
||||
if( ImageCompressed( format ))
|
||||
{
|
||||
switch( format )
|
||||
{
|
||||
@@ -703,7 +704,8 @@ static void GL_SetTextureFormat( gl_texture_t *tex, pixformat_t format, int chan
|
||||
case PF_DXT5: tex->format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
||||
case PF_BC6H_SIGNED: tex->format = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB; break;
|
||||
case PF_BC6H_UNSIGNED: tex->format = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB; break;
|
||||
case PF_BC7: tex->format = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; break;
|
||||
case PF_BC7_SRGB:
|
||||
case PF_BC7_UNORM: tex->format = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; break;
|
||||
case PF_ATI2:
|
||||
if( glConfig.hardware_type == GLHW_RADEON )
|
||||
tex->format = GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI;
|
||||
@@ -1094,7 +1096,7 @@ static void GL_TextureImageRAW( gl_texture_t *tex, GLint side, GLint level, GLin
|
||||
}
|
||||
}
|
||||
|
||||
static void GL_TextureImageDXT( gl_texture_t *tex, GLint side, GLint level, GLint width, GLint height, GLint depth, size_t size, const void *data )
|
||||
static void GL_TextureImageCompressed( gl_texture_t *tex, GLint side, GLint level, GLint width, GLint height, GLint depth, size_t size, const void *data )
|
||||
{
|
||||
GLuint cubeTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;
|
||||
qboolean subImage = FBitSet( tex->flags, TF_IMG_UPLOADED );
|
||||
@@ -1176,7 +1178,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pic->type == PF_BC6H_SIGNED || pic->type == PF_BC6H_UNSIGNED || pic->type == PF_BC7 )
|
||||
if( pic->type == PF_BC6H_SIGNED || pic->type == PF_BC6H_UNSIGNED || pic->type == PF_BC7_UNORM || pic->type == PF_BC7_SRGB )
|
||||
{
|
||||
if( !GL_Support( GL_ARB_TEXTURE_COMPRESSION_BPTC ))
|
||||
{
|
||||
@@ -1217,7 +1219,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
if( buf != NULL && buf >= bufend )
|
||||
gEngfuncs.Host_Error( "GL_UploadTexture: %s image buffer overflow\n", tex->name );
|
||||
|
||||
if( ImageDXT( pic->type ))
|
||||
if( ImageCompressed( pic->type ))
|
||||
{
|
||||
for( j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
{
|
||||
@@ -1225,7 +1227,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth );
|
||||
size = GL_CalcImageSize( pic->type, width, height, tex->depth );
|
||||
GL_TextureImageDXT( tex, i, j, width, height, tex->depth, size, buf );
|
||||
GL_TextureImageCompressed( tex, i, j, width, height, tex->depth, size, buf );
|
||||
tex->size += texsize;
|
||||
buf += size; // move pointer
|
||||
tex->numMips++;
|
||||
@@ -1259,7 +1261,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
|
||||
data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap );
|
||||
else data = buf;
|
||||
|
||||
if( !ImageDXT( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
data = GL_ApplyFilter( data, tex->width, tex->height );
|
||||
|
||||
// mips will be auto-generated if desired
|
||||
@@ -1307,7 +1309,7 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic )
|
||||
|
||||
tex->encode = pic->encode; // share encode method
|
||||
|
||||
if( ImageDXT( pic->type ))
|
||||
if( ImageCompressed( pic->type ))
|
||||
{
|
||||
if( !pic->numMips )
|
||||
tex->flags |= TF_NOMIPMAP; // disable mipmapping by user request
|
||||
@@ -1922,7 +1924,7 @@ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor )
|
||||
return;
|
||||
}
|
||||
|
||||
if( ImageDXT( image->original->type ))
|
||||
if( ImageCompressed( image->original->type ))
|
||||
{
|
||||
gEngfuncs.Con_Printf( S_ERROR "GL_ProcessTexture: can't process compressed texture %s\n", image->name );
|
||||
return;
|
||||
|
||||
@@ -549,24 +549,54 @@ qboolean GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char
|
||||
for( func = funcs; func && func->name; func++ )
|
||||
{
|
||||
// functions are cleared before all the extensions are evaluated
|
||||
if((*func->func = (void *)gEngfuncs.GL_GetProcAddress( func->name )) == NULL )
|
||||
if(( *func->func = (void *)gEngfuncs.GL_GetProcAddress( func->name )) == NULL )
|
||||
{
|
||||
string name;
|
||||
char *end;
|
||||
size_t i = 0;
|
||||
#ifdef XASH_GLES
|
||||
const char *suffixes[] = { "", "EXT", "OES" };
|
||||
#else
|
||||
const char *suffixes[] = { "", "EXT" };
|
||||
#endif
|
||||
|
||||
// HACK: fix ARB names
|
||||
char *str = Q_strstr( func->name, "ARB" );
|
||||
if(str)
|
||||
Q_strncpy( name, func->name, sizeof( name ));
|
||||
if(( end = Q_strstr( name, "ARB" )))
|
||||
{
|
||||
string name;
|
||||
|
||||
Q_strncpy( name, func->name, MAX_STRING );
|
||||
name[str - func->name] = '\0';
|
||||
*func->func = gEngfuncs.GL_GetProcAddress( name );
|
||||
|
||||
if( !*func->func )
|
||||
GL_SetExtension( r_ext, false );
|
||||
*end = '\0';
|
||||
}
|
||||
else
|
||||
// one or more functions are invalid, extension will be disabled
|
||||
else // I need Q_strstrnul
|
||||
{
|
||||
end = name + Q_strlen( name );
|
||||
i++; // skip empty suffix
|
||||
}
|
||||
|
||||
for( ; i < sizeof( suffixes ) / sizeof( suffixes[0] ); i++ )
|
||||
{
|
||||
void *f;
|
||||
|
||||
Q_strncat( name, suffixes[i], sizeof( name ));
|
||||
|
||||
if(( f = gEngfuncs.GL_GetProcAddress( name )))
|
||||
{
|
||||
// GL_GetProcAddress prints errors about missing functions, so tell user that we found it with different name
|
||||
gEngfuncs.Con_Printf( S_NOTE "found %s\n", name );
|
||||
|
||||
*func->func = f;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*end = '\0'; // cut suffix, try next
|
||||
}
|
||||
}
|
||||
|
||||
// not found...
|
||||
if( i == sizeof( suffixes ) / sizeof( suffixes[0] ))
|
||||
{
|
||||
GL_SetExtension( r_ext, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -557,7 +557,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
|
||||
data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap );
|
||||
else data = buf;
|
||||
|
||||
//if( !ImageDXT( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
//if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
// data = GL_ApplyFilter( data, tex->width, tex->height );
|
||||
|
||||
// mips will be auto-generated if desired
|
||||
@@ -663,7 +663,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
|
||||
if( buf != NULL && buf >= bufend )
|
||||
gEngfuncs.Host_Error( "GL_UploadTexture: %s image buffer overflow\n", tex->name );
|
||||
|
||||
if( ImageDXT( pic->type ))
|
||||
if( ImageCompressed( pic->type ))
|
||||
{
|
||||
for( j = 0; j < Q_max( 1, pic->numMips ); j++ )
|
||||
{
|
||||
@@ -671,7 +671,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
|
||||
height = Q_max( 1, ( tex->height >> j ));
|
||||
texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth );
|
||||
size = GL_CalcImageSize( pic->type, width, height, tex->depth );
|
||||
GL_TextureImageDXT( tex, i, j, width, height, tex->depth, size, buf );
|
||||
GL_TextureImageCompressed( tex, i, j, width, height, tex->depth, size, buf );
|
||||
tex->size += texsize;
|
||||
buf += size; // move pointer
|
||||
tex->numMips++;
|
||||
@@ -705,7 +705,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic )
|
||||
data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap );
|
||||
else data = buf;
|
||||
|
||||
if( !ImageDXT( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA ))
|
||||
data = GL_ApplyFilter( data, tex->width, tex->height );
|
||||
|
||||
// mips will be auto-generated if desired
|
||||
@@ -753,7 +753,7 @@ static void GL_ProcessImage( image_t *tex, rgbdata_t *pic )
|
||||
if( tex->flags & TF_FORCE_COLOR ) pic->flags |= IMAGE_HAS_COLOR;
|
||||
if( pic->flags & IMAGE_HAS_ALPHA ) tex->flags |= TF_HAS_ALPHA;
|
||||
|
||||
if( ImageDXT( pic->type ))
|
||||
if( ImageCompressed( pic->type ))
|
||||
{
|
||||
if( !pic->numMips )
|
||||
tex->flags |= TF_NOMIPMAP; // disable mipmapping by user request
|
||||
@@ -1178,7 +1178,7 @@ void GAME_EXPORT GL_ProcessTexture( int texnum, float gamma, int topColor, int b
|
||||
return;
|
||||
}
|
||||
|
||||
if( ImageDXT( image->original->type ))
|
||||
if( ImageCompressed( image->original->type ))
|
||||
{
|
||||
gEngfuncs.Con_Printf( S_ERROR "GL_ProcessTexture: can't process compressed texture %s\n", image->name );
|
||||
return;
|
||||
|
||||
@@ -41,21 +41,17 @@ static void SequenceNameFix( void )
|
||||
{
|
||||
int i, j, counter;
|
||||
qboolean hasduplicates = false;
|
||||
mstudioseqdesc_t *seqdesc, *seqdesc1;
|
||||
mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ), *seqdesc1;
|
||||
|
||||
for( i = 0; i < model_hdr->numseq; i++ )
|
||||
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
|
||||
{
|
||||
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
|
||||
|
||||
counter = 1;
|
||||
|
||||
for( j = 0; j < model_hdr->numseq; j++ )
|
||||
{
|
||||
seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + j;
|
||||
seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
|
||||
|
||||
for( j = 0; j < model_hdr->numseq; ++j, ++seqdesc1 )
|
||||
if( j != i && !Q_strncmp( seqdesc1->label, seqdesc->label, sizeof( seqdesc1->label ) ) )
|
||||
Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "%s_%i", seqdesc1->label, ++counter );
|
||||
}
|
||||
|
||||
if( counter > 1 )
|
||||
{
|
||||
@@ -79,15 +75,11 @@ BoneNameFix
|
||||
static void BoneNameFix( void )
|
||||
{
|
||||
int i, counter = 0;
|
||||
mstudiobone_t *bone;
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; i++ )
|
||||
{
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
|
||||
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++bone )
|
||||
if( bone->name[0] == '\0' )
|
||||
Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++counter );
|
||||
}
|
||||
|
||||
if( counter )
|
||||
printf( "WARNING: Gived name to %i unnamed bone(s).\n", counter );
|
||||
@@ -266,6 +258,8 @@ static void ShowHelp( const char *app_name )
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
puts( "\nHalf-Life Studio Model Decompiler " APP_VERSION );
|
||||
puts( "Copyright Flying With Gauss 2020 (c) " );
|
||||
puts( "--------------------------------------------------" );
|
||||
@@ -273,6 +267,7 @@ int main( int argc, char *argv[] )
|
||||
if( argc == 1 )
|
||||
{
|
||||
ShowHelp( argv[0] );
|
||||
ret = 2;
|
||||
goto end;
|
||||
}
|
||||
else if( argc == 3 )
|
||||
@@ -280,6 +275,7 @@ int main( int argc, char *argv[] )
|
||||
if( Q_strlen( argv[2] ) > MAX_SYSPATH - 2 )
|
||||
{
|
||||
fputs( "ERROR: Destination path is too long.\n", stderr );
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -287,7 +283,10 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
if( !LoadActivityList( argv[0] ) || !LoadMDL( argv[1] ) )
|
||||
{
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
WriteQCScript();
|
||||
WriteSMD();
|
||||
@@ -298,6 +297,6 @@ int main( int argc, char *argv[] )
|
||||
end:
|
||||
puts( "--------------------------------------------------" );
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ WriteSkinFamilyInfo
|
||||
static void WriteSkinFamilyInfo( FILE *fp )
|
||||
{
|
||||
int i, j, k;
|
||||
short *skinref, index;
|
||||
short *skinref, *index;
|
||||
mstudiotexture_t *texture;
|
||||
|
||||
if( texture_hdr->numskinfamilies < 2 )
|
||||
@@ -260,23 +260,22 @@ static void WriteSkinFamilyInfo( FILE *fp )
|
||||
fputs( "$texturegroup \"skinfamilies\"\n{\n", fp );
|
||||
|
||||
skinref = (short *)( (byte *)texture_hdr + texture_hdr->skinindex );
|
||||
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
|
||||
|
||||
for( i = 0; i < texture_hdr->numskinfamilies; ++i )
|
||||
{
|
||||
fputs( "\t{\n", fp );
|
||||
|
||||
for( j = 0; j < texture_hdr->numskinref; ++j )
|
||||
{
|
||||
index = *( skinref + i * texture_hdr->numskinref + j );
|
||||
index = skinref + i * texture_hdr->numskinref;
|
||||
|
||||
for( j = 0; j < texture_hdr->numskinref; ++j, ++index )
|
||||
{
|
||||
for( k = 0; k < texture_hdr->numskinfamilies; ++k )
|
||||
{
|
||||
if( index == *( skinref + k * texture_hdr->numskinref + j ) )
|
||||
if( *index == *( skinref + k * texture_hdr->numskinref + j ) )
|
||||
continue;
|
||||
|
||||
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + index;
|
||||
|
||||
fprintf( fp, "\t\t\"%s\"\n", texture->name );
|
||||
fprintf( fp, "\t\t\"%s\"\n", texture[*index].name );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -301,15 +300,13 @@ static void WriteAttachmentInfo( FILE *fp )
|
||||
if( !model_hdr->numattachments )
|
||||
return;
|
||||
|
||||
attachment = (mstudioattachment_t *)( (byte *)model_hdr + model_hdr->attachmentindex );
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fprintf( fp, "// %i attachment%s\n", model_hdr->numattachments, model_hdr->numattachments > 1 ? "s" : "" );
|
||||
|
||||
for( i = 0; i < model_hdr->numattachments; ++i )
|
||||
{
|
||||
attachment = (mstudioattachment_t *)( (byte *)model_hdr + model_hdr->attachmentindex ) + i;
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + attachment->bone;
|
||||
|
||||
fprintf( fp, "$attachment %i \"%s\" %f %f %f\n", i, bone->name, attachment->org[0], attachment->org[1], attachment->org[2] );
|
||||
}
|
||||
for( i = 0; i < model_hdr->numattachments; ++i, ++attachment )
|
||||
fprintf( fp, "$attachment %i \"%s\" %f %f %f\n", i, bone[attachment->bone].name, attachment->org[0], attachment->org[1], attachment->org[2] );
|
||||
|
||||
fputs( "\n", fp );
|
||||
}
|
||||
@@ -322,20 +319,18 @@ WriteBodyGroupInfo
|
||||
static void WriteBodyGroupInfo( FILE *fp )
|
||||
{
|
||||
int i, j;
|
||||
mstudiobodyparts_t *bodypart;
|
||||
mstudiobodyparts_t *bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex );
|
||||
mstudiomodel_t *model;
|
||||
char modelname[64];
|
||||
|
||||
fprintf( fp, "// %i reference mesh%s\n", model_hdr->numbodyparts, model_hdr->numbodyparts > 1 ? "es" : "" );
|
||||
|
||||
for( i = 0; i < model_hdr->numbodyparts; ++i )
|
||||
for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
|
||||
{
|
||||
bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex ) + i;
|
||||
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
|
||||
|
||||
if( bodypart->nummodels == 1 )
|
||||
{
|
||||
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
|
||||
|
||||
COM_FileBase( model->name, modelname, sizeof( modelname ));
|
||||
|
||||
fprintf( fp, "$body \"%s\" \"%s\"\n", bodypart->name, modelname );
|
||||
@@ -346,10 +341,8 @@ static void WriteBodyGroupInfo( FILE *fp )
|
||||
|
||||
fputs( "{\n", fp );
|
||||
|
||||
for( j = 0; j < bodypart->nummodels; ++j )
|
||||
for( j = 0; j < bodypart->nummodels; ++j, ++model )
|
||||
{
|
||||
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex ) + j;
|
||||
|
||||
if( !Q_strncmp( model->name, "blank", 5 ) )
|
||||
{
|
||||
fputs( "\tblank\n", fp );
|
||||
@@ -382,13 +375,13 @@ static void WriteControllerInfo( FILE *fp )
|
||||
if( !model_hdr->numbonecontrollers )
|
||||
return;
|
||||
|
||||
bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex );
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fprintf( fp, "// %i bone controller%s\n", model_hdr->numbonecontrollers, model_hdr->numbonecontrollers > 1 ? "s" : "" );
|
||||
|
||||
for( i = 0; i < model_hdr->numbonecontrollers; ++i )
|
||||
for( i = 0; i < model_hdr->numbonecontrollers; ++i, ++bonecontroller )
|
||||
{
|
||||
bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex ) + i;
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + bonecontroller->bone;
|
||||
|
||||
GetMotionTypeString( bonecontroller->type & ~STUDIO_RLOOP, motion_types, sizeof( motion_types ), false );
|
||||
|
||||
fputs( "$controller ", fp );
|
||||
@@ -399,7 +392,7 @@ static void WriteControllerInfo( FILE *fp )
|
||||
fprintf( fp, "%i", bonecontroller->index );
|
||||
|
||||
fprintf( fp, " \"%s\" %s %f %f\n",
|
||||
bone->name, motion_types,
|
||||
bone[bonecontroller->bone].name, motion_types,
|
||||
bonecontroller->start, bonecontroller->end );
|
||||
}
|
||||
|
||||
@@ -420,18 +413,16 @@ static void WriteHitBoxInfo( FILE *fp )
|
||||
if( !model_hdr->numhitboxes )
|
||||
return;
|
||||
|
||||
hitbox = (mstudiobbox_t *)( (byte *)model_hdr + model_hdr->hitboxindex );
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fprintf( fp, "// %i hit box%s\n", model_hdr->numhitboxes, model_hdr->numhitboxes > 1 ? "es" : "" );
|
||||
|
||||
for( i = 0; i < model_hdr->numhitboxes; i++ )
|
||||
{
|
||||
hitbox = (mstudiobbox_t *)( (byte *)model_hdr + model_hdr->hitboxindex ) + i;
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + hitbox->bone;
|
||||
|
||||
for( i = 0; i < model_hdr->numhitboxes; ++i, ++hitbox )
|
||||
fprintf( fp, "$hbox %i \"%s\" %f %f %f %f %f %f\n",
|
||||
hitbox->group, bone->name,
|
||||
hitbox->group, bone[hitbox->bone].name,
|
||||
hitbox->bbmin[0], hitbox->bbmin[1], hitbox->bbmin[2],
|
||||
hitbox->bbmax[0], hitbox->bbmax[1], hitbox->bbmax[2] );
|
||||
}
|
||||
|
||||
fputs( "\n", fp );
|
||||
}
|
||||
@@ -477,19 +468,18 @@ static void WriteSequenceInfo( FILE *fp )
|
||||
|
||||
if( model_hdr->numseq > 0 )
|
||||
fprintf( fp, "// %i animation sequence%s\n", model_hdr->numseq, model_hdr->numseq > 1 ? "s" : "" );
|
||||
else return;
|
||||
|
||||
for( i = 0; i < model_hdr->numseq; ++i )
|
||||
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
|
||||
|
||||
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
|
||||
{
|
||||
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
|
||||
|
||||
fprintf( fp, "$sequence \"%s\" {\n", seqdesc->label );
|
||||
|
||||
if( seqdesc->numblends > 1 )
|
||||
{
|
||||
for( j = 0; j < seqdesc->numblends; j++ )
|
||||
{
|
||||
fprintf( fp, "\t\"%s_blend%02i\"\n", seqdesc->label, j + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -513,18 +503,21 @@ static void WriteSequenceInfo( FILE *fp )
|
||||
}
|
||||
}
|
||||
|
||||
if( seqdesc->blendtype[0] )
|
||||
if( seqdesc->numblends > 1 )
|
||||
{
|
||||
GetMotionTypeString( seqdesc->blendtype[0], motion_types, sizeof( motion_types ), false );
|
||||
|
||||
fprintf( fp, "\tblend %s %.0f %.0f\n",
|
||||
motion_types, seqdesc->blendstart[0], seqdesc->blendend[0] );
|
||||
|
||||
if( !seqdesc->blendtype[0] )
|
||||
printf( "WARNING: Something wrong with blending type for sequence: %s\n", seqdesc->label );
|
||||
}
|
||||
|
||||
for( j = 0; j < seqdesc->numevents; j++ )
|
||||
{
|
||||
event = (mstudioevent_t *)( (byte *)model_hdr + seqdesc->eventindex ) + j;
|
||||
event = (mstudioevent_t *)( (byte *)model_hdr + seqdesc->eventindex );
|
||||
|
||||
for( j = 0; j < seqdesc->numevents; ++j, ++event )
|
||||
{
|
||||
fprintf( fp, "\t{ event %i %i", event->event, event->frame );
|
||||
|
||||
if( event->options[0] != '\0' )
|
||||
@@ -613,7 +606,7 @@ void WriteQCScript( void )
|
||||
|
||||
WriteBodyGroupInfo( fp );
|
||||
|
||||
fprintf( fp, "$flags %i\n\n", model_hdr->flags );
|
||||
fprintf( fp, "$flags %u\n\n", model_hdr->flags &~( STUDIO_HAS_BONEINFO | STUDIO_HAS_BONEWEIGHTS ) );
|
||||
fprintf( fp, "$eyeposition %f %f %f\n\n", model_hdr->eyeposition[0], model_hdr->eyeposition[1], model_hdr->eyeposition[2] );
|
||||
|
||||
if( !model_hdr->numtextures )
|
||||
@@ -621,6 +614,10 @@ void WriteQCScript( void )
|
||||
|
||||
WriteSkinFamilyInfo( fp );
|
||||
WriteTextureRenderMode( fp );
|
||||
|
||||
if( model_hdr->flags & ( STUDIO_HAS_BONEINFO | STUDIO_HAS_BONEWEIGHTS ) )
|
||||
fputs( "$boneweights\n\n", fp );
|
||||
|
||||
WriteAttachmentInfo( fp );
|
||||
|
||||
fprintf( fp, "$bbox %f %f %f", model_hdr->min[0], model_hdr->min[1], model_hdr->min[2] );
|
||||
|
||||
@@ -25,17 +25,18 @@ GNU General Public License for more details.
|
||||
#include "smd.h"
|
||||
|
||||
static matrix3x4 *bonetransform;
|
||||
static matrix3x4 *worldtransform;
|
||||
|
||||
/*
|
||||
============
|
||||
CreateBoneTransformMatrices
|
||||
============
|
||||
*/
|
||||
static qboolean CreateBoneTransformMatrices( void )
|
||||
static qboolean CreateBoneTransformMatrices( matrix3x4 **matrix )
|
||||
{
|
||||
bonetransform = calloc( model_hdr->numbones, sizeof( matrix3x4 ) );
|
||||
*matrix = calloc( model_hdr->numbones, sizeof( matrix3x4 ) );
|
||||
|
||||
if( !bonetransform )
|
||||
if( !*matrix )
|
||||
{
|
||||
fputs( "ERROR: Couldn't allocate memory for bone transformation matrices!\n", stderr );
|
||||
return false;
|
||||
@@ -52,14 +53,12 @@ FillBoneTransformMatrices
|
||||
static void FillBoneTransformMatrices( void )
|
||||
{
|
||||
int i;
|
||||
mstudiobone_t *bone;
|
||||
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
matrix3x4 bonematrix;
|
||||
vec4_t q;
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; i++ )
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++bone )
|
||||
{
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
|
||||
|
||||
AngleQuaternion( &bone->value[3], q, true );
|
||||
Matrix3x4_FromOriginQuat( bonematrix, q, bone->value );
|
||||
|
||||
@@ -73,14 +72,28 @@ static void FillBoneTransformMatrices( void )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
FillWorldTransformMatrices
|
||||
============
|
||||
*/
|
||||
static void FillWorldTransformMatrices( void )
|
||||
{
|
||||
int i;
|
||||
mstudioboneinfo_t *boneinfo = (mstudioboneinfo_t *)( (byte *)model_hdr + model_hdr->boneindex + model_hdr->numbones * sizeof( mstudiobone_t ) );
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++boneinfo )
|
||||
Matrix3x4_ConcatTransforms( worldtransform[i], bonetransform[i], boneinfo->poseToBone );
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
RemoveBoneTransformMatrices
|
||||
============
|
||||
*/
|
||||
static void RemoveBoneTransformMatrices( void )
|
||||
static void RemoveBoneTransformMatrices( matrix3x4 **matrix )
|
||||
{
|
||||
free( bonetransform );
|
||||
free( *matrix );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,16 +184,12 @@ WriteNodes
|
||||
static void WriteNodes( FILE *fp )
|
||||
{
|
||||
int i;
|
||||
mstudiobone_t *bone;
|
||||
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fputs( "nodes\n", fp );
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; i++ )
|
||||
{
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++bone )
|
||||
fprintf( fp, "%3i \"%s\" %i\n", i, bone->name, bone->parent );
|
||||
}
|
||||
|
||||
fputs( "end\n", fp );
|
||||
}
|
||||
@@ -193,15 +202,13 @@ WriteSkeleton
|
||||
static void WriteSkeleton( FILE *fp )
|
||||
{
|
||||
int i, j;
|
||||
mstudiobone_t *bone;
|
||||
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fputs( "skeleton\n", fp );
|
||||
fputs( "time 0\n", fp );
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; i++ )
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++bone )
|
||||
{
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
|
||||
|
||||
fprintf( fp, "%3i", i );
|
||||
|
||||
for( j = 0; j < 6; j++ )
|
||||
@@ -220,32 +227,24 @@ WriteTriangleInfo
|
||||
*/
|
||||
static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t *texture, mstudiotrivert_t **triverts, qboolean isevenstrip )
|
||||
{
|
||||
int i, indices[3];
|
||||
int vert_index;
|
||||
int norm_index;
|
||||
int bone_index;
|
||||
float s, t, u, v;
|
||||
byte *vertbone;
|
||||
vec3_t *studioverts;
|
||||
vec3_t *studionorms;
|
||||
vec3_t vert, norm;
|
||||
|
||||
if( isevenstrip )
|
||||
{
|
||||
indices[0] = 1;
|
||||
indices[1] = 2;
|
||||
indices[2] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
indices[0] = 0;
|
||||
indices[1] = 1;
|
||||
indices[2] = 2;
|
||||
}
|
||||
int i, j, k, l, index;
|
||||
int vert_index;
|
||||
int norm_index;
|
||||
int bone_index;
|
||||
int valid_bones;
|
||||
float s, t, u, v;
|
||||
byte *vertbone;
|
||||
vec3_t *studioverts;
|
||||
vec3_t *studionorms;
|
||||
vec3_t vert, norm;
|
||||
float weights[MAXSTUDIOBONEWEIGHTS], oldweight, totalweight;
|
||||
matrix3x4 bonematrix[MAXSTUDIOBONEWEIGHTS], skinmatrix, *pskinmatrix;
|
||||
mstudioboneweight_t *studioboneweights;
|
||||
|
||||
vertbone = ( (byte *)model_hdr + model->vertinfoindex );
|
||||
studioverts = (vec3_t *)( (byte *)model_hdr + model->vertindex );
|
||||
studionorms = (vec3_t *)( (byte *)model_hdr + model->normindex );
|
||||
studioboneweights = (mstudioboneweight_t *)( (byte *)model_hdr + model->blendvertinfoindex );
|
||||
|
||||
s = 1.0f / texture->width;
|
||||
t = 1.0f / texture->height;
|
||||
@@ -254,30 +253,76 @@ static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
vert_index = triverts[indices[i]]->vertindex;
|
||||
norm_index = triverts[indices[i]]->normindex;
|
||||
index = isevenstrip ? ( i + 1 ) % 3 : i;
|
||||
vert_index = triverts[index]->vertindex;
|
||||
norm_index = triverts[index]->normindex;
|
||||
bone_index = vertbone[vert_index];
|
||||
|
||||
Matrix3x4_VectorTransform( bonetransform[bone_index], studioverts[vert_index], vert );
|
||||
Matrix3x4_VectorRotate( bonetransform[bone_index], studionorms[norm_index], norm );
|
||||
if( model_hdr->flags & STUDIO_HAS_BONEWEIGHTS )
|
||||
{
|
||||
valid_bones = 0, totalweight = 0;
|
||||
memset( skinmatrix, 0, sizeof( matrix3x4 ) );
|
||||
|
||||
for( j = 0; j < MAXSTUDIOBONEWEIGHTS; ++j )
|
||||
if( studioboneweights[vert_index].bone[j] != -1 )
|
||||
valid_bones++;
|
||||
|
||||
for( j = 0; j < valid_bones; ++j )
|
||||
{
|
||||
Matrix3x4_Copy( bonematrix[j], worldtransform[studioboneweights[vert_index].bone[j]] );
|
||||
weights[j] = studioboneweights[vert_index].weight[j] / 255.0f;
|
||||
totalweight += weights[j];
|
||||
}
|
||||
|
||||
oldweight = weights[0];
|
||||
|
||||
if( totalweight < 1.0f )
|
||||
weights[0] += 1.0f - totalweight;
|
||||
|
||||
for( j = 0; j < valid_bones; ++j )
|
||||
for( k = 0; k < 3; ++k )
|
||||
for( l = 0; l < 4; ++l )
|
||||
skinmatrix[k][l] += bonematrix[j][k][l] * weights[j];
|
||||
|
||||
pskinmatrix = &skinmatrix;
|
||||
}
|
||||
else
|
||||
pskinmatrix = &bonetransform[bone_index];
|
||||
|
||||
Matrix3x4_VectorTransform( *pskinmatrix, studioverts[vert_index], vert );
|
||||
Matrix3x4_VectorRotate( *pskinmatrix, studionorms[norm_index], norm );
|
||||
VectorNormalize( norm );
|
||||
|
||||
if( texture->flags & STUDIO_NF_UV_COORDS )
|
||||
{
|
||||
u = HalfToFloat( triverts[indices[i]]->s );
|
||||
v = -HalfToFloat( triverts[indices[i]]->t );
|
||||
u = HalfToFloat( triverts[index]->s );
|
||||
v = -HalfToFloat( triverts[index]->t );
|
||||
}
|
||||
else
|
||||
{
|
||||
u = ( triverts[indices[i]]->s + 1.0f ) * s;
|
||||
v = 1.0f - triverts[indices[i]]->t * t;
|
||||
u = ( triverts[index]->s + 1.0f ) * s;
|
||||
v = 1.0f - triverts[index]->t * t;
|
||||
}
|
||||
|
||||
fprintf( fp, "%3i %f %f %f %f %f %f %f %f\n",
|
||||
fprintf( fp, "%3i %f %f %f %f %f %f %f %f",
|
||||
bone_index,
|
||||
vert[0], vert[1], vert[2],
|
||||
norm[0], norm[1], norm[2],
|
||||
u, v );
|
||||
|
||||
if( model_hdr->flags & STUDIO_HAS_BONEWEIGHTS )
|
||||
{
|
||||
fprintf( fp, " %d", valid_bones );
|
||||
|
||||
weights[0] = oldweight;
|
||||
|
||||
for( j = 0; j < valid_bones; ++j )
|
||||
fprintf( fp, " %d %f",
|
||||
studioboneweights[vert_index].bone[j],
|
||||
weights[j] );
|
||||
}
|
||||
|
||||
fputs( "\n", fp );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,16 +334,15 @@ WriteTriangles
|
||||
static void WriteTriangles( FILE *fp, mstudiomodel_t *model )
|
||||
{
|
||||
int i, j, k;
|
||||
mstudiomesh_t *mesh;
|
||||
mstudiomesh_t *mesh = (mstudiomesh_t *)( (byte *)model_hdr + model->meshindex );
|
||||
mstudiotexture_t *texture;
|
||||
mstudiotrivert_t *triverts[3];
|
||||
short *tricmds;
|
||||
|
||||
fputs( "triangles\n", fp );
|
||||
|
||||
for( i = 0; i < model->nummesh; i++ )
|
||||
for( i = 0; i < model->nummesh; ++i, ++mesh )
|
||||
{
|
||||
mesh = (mstudiomesh_t *)( (byte *)model_hdr + model->meshindex ) + i;
|
||||
tricmds = (short *)( (byte *)model_hdr + mesh->triindex );
|
||||
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + mesh->skinref;
|
||||
|
||||
@@ -385,22 +429,19 @@ static void WriteFrameInfo( FILE *fp, mstudioanim_t *anim, mstudioseqdesc_t *seq
|
||||
int i, j;
|
||||
float scale;
|
||||
vec_t motion[6]; // x, y, z, xr, yr, zr
|
||||
mstudiobone_t *bone;
|
||||
mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
|
||||
|
||||
fprintf( fp, "time %i\n", frame );
|
||||
|
||||
for( i = 0; i < model_hdr->numbones; i++, anim++ )
|
||||
for( i = 0; i < model_hdr->numbones; ++i, ++anim, ++bone )
|
||||
{
|
||||
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
|
||||
|
||||
CalcBonePosition( anim, bone, motion, frame );
|
||||
|
||||
if( bone->parent == -1 )
|
||||
{
|
||||
scale = frame / (float)( seqdesc->numframes - 1 );
|
||||
|
||||
for( j = 0; j < 3; j++ )
|
||||
motion[j] += scale * seqdesc->linearmovement[j];
|
||||
VectorMA( motion, scale, seqdesc->linearmovement, motion );
|
||||
|
||||
ProperBoneRotationZ( motion, 270.0f );
|
||||
}
|
||||
@@ -452,19 +493,27 @@ static void WriteReferences( void )
|
||||
char name[64];
|
||||
char filename[MAX_SYSPATH];
|
||||
|
||||
if( !CreateBoneTransformMatrices() )
|
||||
if( !CreateBoneTransformMatrices( &bonetransform ) )
|
||||
return;
|
||||
|
||||
FillBoneTransformMatrices();
|
||||
|
||||
for( i = 0; i < model_hdr->numbodyparts; i++ )
|
||||
if( model_hdr->flags & STUDIO_HAS_BONEINFO )
|
||||
{
|
||||
bodypart = (mstudiobodyparts_t *)( (byte *)model_hdr + model_hdr->bodypartindex ) + i;
|
||||
if( !CreateBoneTransformMatrices( &worldtransform ) )
|
||||
return;
|
||||
|
||||
for( j = 0; j < bodypart->nummodels; j++ )
|
||||
FillWorldTransformMatrices();
|
||||
}
|
||||
|
||||
bodypart = (mstudiobodyparts_t *)( (byte *)model_hdr + model_hdr->bodypartindex );
|
||||
|
||||
for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
|
||||
{
|
||||
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
|
||||
|
||||
for( j = 0; j < bodypart->nummodels; ++j, ++model )
|
||||
{
|
||||
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex ) + j;
|
||||
|
||||
if( !Q_strncmp( model->name, "blank", 5 ) )
|
||||
continue;
|
||||
|
||||
@@ -475,8 +524,7 @@ static void WriteReferences( void )
|
||||
if( len == -1 )
|
||||
{
|
||||
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", name );
|
||||
RemoveBoneTransformMatrices();
|
||||
return;
|
||||
goto _fail;
|
||||
}
|
||||
|
||||
fp = fopen( filename, "w" );
|
||||
@@ -484,8 +532,7 @@ static void WriteReferences( void )
|
||||
if( !fp )
|
||||
{
|
||||
fprintf( stderr, "ERROR: Can't write %s\n", filename );
|
||||
RemoveBoneTransformMatrices();
|
||||
return;
|
||||
goto _fail;
|
||||
}
|
||||
|
||||
fputs( "version 1\n", fp );
|
||||
@@ -500,7 +547,11 @@ static void WriteReferences( void )
|
||||
}
|
||||
}
|
||||
|
||||
RemoveBoneTransformMatrices();
|
||||
_fail:
|
||||
RemoveBoneTransformMatrices( &bonetransform );
|
||||
|
||||
if( model_hdr->flags & STUDIO_HAS_BONEINFO )
|
||||
RemoveBoneTransformMatrices( &worldtransform );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -514,12 +565,10 @@ static void WriteSequences( void )
|
||||
int len;
|
||||
FILE *fp;
|
||||
char filename[MAX_SYSPATH];
|
||||
mstudioseqdesc_t *seqdesc;
|
||||
mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
|
||||
|
||||
for( i = 0; i < model_hdr->numseq; i++ )
|
||||
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
|
||||
{
|
||||
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
|
||||
|
||||
for( j = 0; j < seqdesc->numblends; j++ )
|
||||
{
|
||||
if( seqdesc->numblends == 1 )
|
||||
|
||||
@@ -33,7 +33,7 @@ static void WriteBMP( mstudiotexture_t *texture )
|
||||
int i, len;
|
||||
FILE *fp;
|
||||
const byte *p;
|
||||
byte *palette, *pic, *buf;
|
||||
byte *palette, *pic;
|
||||
char filename[MAX_SYSPATH], texturename[64];
|
||||
rgba_t rgba_palette[256];
|
||||
bmp_t bmp_hdr = {0,};
|
||||
@@ -87,23 +87,17 @@ static void WriteBMP( mstudiotexture_t *texture )
|
||||
|
||||
fwrite( rgba_palette, sizeof( rgba_palette ), 1, fp );
|
||||
|
||||
buf = malloc( texture_size );
|
||||
|
||||
p = pic;
|
||||
p += ( bmp_hdr.height - 1 ) * bmp_hdr.width;
|
||||
|
||||
for( i = 0; i < bmp_hdr.height; i++ )
|
||||
{
|
||||
memcpy( buf + bmp_hdr.width * i, p, bmp_hdr.width );
|
||||
fwrite( p, bmp_hdr.width, 1, fp );
|
||||
p -= bmp_hdr.width;
|
||||
}
|
||||
|
||||
fwrite( buf, texture_size, 1, fp );
|
||||
|
||||
fclose( fp );
|
||||
|
||||
free( buf );
|
||||
|
||||
printf( "Texture: %s\n", filename );
|
||||
}
|
||||
|
||||
@@ -115,13 +109,9 @@ WriteTextures
|
||||
void WriteTextures( void )
|
||||
{
|
||||
int i;
|
||||
mstudiotexture_t *texture;
|
||||
|
||||
for( i = 0; i < texture_hdr->numtextures; i++ )
|
||||
{
|
||||
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + i;
|
||||
mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
|
||||
|
||||
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
|
||||
WriteBMP( texture );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user