Server: add support for more ways of loading HLBSP material definitions.
Explanation is provided under docs/hlmaterials, about the ways you can go about this and which methods provided by the community are supported
This commit is contained in:
parent
44ab18793c
commit
6e38bac564
4 changed files with 132 additions and 21 deletions
56
doc/hlmaterials
Normal file
56
doc/hlmaterials
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
hlmaterials - Nuclide Documentation
|
||||||
|
Written by Gethyn ThomasQuail, 6th April 2021
|
||||||
|
|
||||||
|
This document gives a general overview of what the materials.txt files is,
|
||||||
|
and how it's used in Nuclide, and why the decisions were chosen for the
|
||||||
|
current implementation. It is not an in-depth explanation of the format
|
||||||
|
itself.
|
||||||
|
|
||||||
|
The materials.txt is how the GoldSrc engine defined sounds for various
|
||||||
|
textures throughout the game. For example, crates make "wood" sounds,
|
||||||
|
vents produce metallic feedback, etc. It is an analogue to surfaceparms
|
||||||
|
for those familiar with idTech engines, this was just Valve Software's
|
||||||
|
way of doing it before adopting standards.
|
||||||
|
|
||||||
|
In stock Half-Life, this file is located at:
|
||||||
|
|
||||||
|
sounds/materials.txt
|
||||||
|
|
||||||
|
It is allowed to be overwritten by a modification, and users could customize
|
||||||
|
the file on the client-side only for themselves. This means there was no
|
||||||
|
map specific materials, and mods could not inherit HL's materials, so
|
||||||
|
mods would always have to manage a nearly duplicate file if they desired
|
||||||
|
custom texture sounds.
|
||||||
|
|
||||||
|
A few mods tried to remedy this problem, the following below is methods
|
||||||
|
documented so far:
|
||||||
|
|
||||||
|
- maps/MAPNAME.mat
|
||||||
|
Introduced in The Wastes.
|
||||||
|
|
||||||
|
- maps/MAPNAME_materials.txt
|
||||||
|
Convention by Andrew Lucas, creator of Trinity SDK, modeled after
|
||||||
|
MAPNAME_details.txt
|
||||||
|
|
||||||
|
- materials_file "PATH/FILE.txt" via "worldspawn" entity
|
||||||
|
Introduced in Sven Co-op 5.0
|
||||||
|
|
||||||
|
All these methods are supported by Nuclide, as one goal is to implement
|
||||||
|
conventions by not only Valve but the community as well.
|
||||||
|
|
||||||
|
In addition Nuclide has also implemented a way of giving modifications
|
||||||
|
their own inheritable materials file:
|
||||||
|
|
||||||
|
sounds/materials_UNIQUENAME.txt
|
||||||
|
|
||||||
|
The idea here is that any mod or even map pack can include ONLY the textures
|
||||||
|
used, and no longer will anyone have to manage a near-clone of materials.txt
|
||||||
|
|
||||||
|
For repackaging or modding purposes, if you desire to give your map custom
|
||||||
|
sound definitions, we recommend The Wastes method for individual maps, while
|
||||||
|
the Nuclide method should be used for Mods or Map Packs. We find these to be
|
||||||
|
the most clean and efficient way.
|
||||||
|
|
||||||
|
NOTE: We recommend only using materials text files for GoldSrc related modding purposes. It is inefficient for modern projects as there are much better
|
||||||
|
standards already supported in Nuclide. Keep in mind, it takes memory to load
|
||||||
|
big text files, and lots of text files adds up over play sessions.
|
|
@ -421,28 +421,9 @@ initents(void)
|
||||||
/* sound shader init */
|
/* sound shader init */
|
||||||
Sound_Init();
|
Sound_Init();
|
||||||
|
|
||||||
|
/* only bother doing so on Half-Life BSP */
|
||||||
if (serverkeyfloat("*bspversion") == BSPVER_HL) {
|
if (serverkeyfloat("*bspversion") == BSPVER_HL) {
|
||||||
/* load materials.txt because someone thought this was the best idea */
|
HLMaterials_Init();
|
||||||
filestream fileMaterial = fopen("sound/materials.txt", FILE_READ);
|
|
||||||
hashMaterials = __NULL__;
|
|
||||||
hashMaterials = hash_createtab(2, HASH_ADD);
|
|
||||||
|
|
||||||
if (fileMaterial >= 0) {
|
|
||||||
string sTemp;
|
|
||||||
while ((sTemp = fgets(fileMaterial))) {
|
|
||||||
/* tokenize and just parse this stuff in */
|
|
||||||
if (tokenize_console(sTemp) == 2) {
|
|
||||||
string mat_type;
|
|
||||||
string tex_name;
|
|
||||||
mat_type = strtoupper(argv(0));
|
|
||||||
tex_name = Materials_FixName(strtolower(argv(1)));
|
|
||||||
hash_add(hashMaterials, strtolower(argv(1)), str2chr(mat_type, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fileMaterial);
|
|
||||||
} else {
|
|
||||||
print("Failed to load sound/materials.txt!\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PMove_Init();
|
PMove_Init();
|
||||||
|
|
73
src/server/hlmaterials.qc
Normal file
73
src/server/hlmaterials.qc
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* FIXME: world.... sigh, we should box this into a worldspawn class */
|
||||||
|
.string materials_file;
|
||||||
|
|
||||||
|
void
|
||||||
|
HLMaterials_Load(string filename)
|
||||||
|
{
|
||||||
|
filestream fileMaterial;
|
||||||
|
string sTemp;
|
||||||
|
string mat_type;
|
||||||
|
string tex_name;
|
||||||
|
|
||||||
|
fileMaterial = fopen(filename, FILE_READ);
|
||||||
|
if (fileMaterial >= 0) {
|
||||||
|
print(strcat("^2HLMaterials_Load: loading ", filename,"!\n"));
|
||||||
|
while ((sTemp = fgets(fileMaterial))) {
|
||||||
|
/* tokenize and just parse this stuff in */
|
||||||
|
if (tokenize_console(sTemp) == 2) {
|
||||||
|
mat_type = strtoupper(argv(0));
|
||||||
|
tex_name = Materials_FixName(strtolower(argv(1)));
|
||||||
|
hash_add(hashMaterials, strtolower(argv(1)), str2chr(mat_type, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fileMaterial);
|
||||||
|
} else {
|
||||||
|
dprint(strcat("^1Failed to load ", filename,"!\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HLMaterials_Init(void)
|
||||||
|
{
|
||||||
|
/* load materials.txt because someone thought this was the best idea */
|
||||||
|
|
||||||
|
hashMaterials = __NULL__;
|
||||||
|
hashMaterials = hash_createtab(2, HASH_ADD);
|
||||||
|
|
||||||
|
/* the base definition, every GoldSrc game has this */
|
||||||
|
HLMaterials_Load("sound/materials.txt");
|
||||||
|
|
||||||
|
/* Sven Coop 5.0 does this, fun. */
|
||||||
|
if (world.materials_file)
|
||||||
|
HLMaterials_Load(world.materials_file);
|
||||||
|
|
||||||
|
/* search through our sound dir for material definitions */
|
||||||
|
searchhandle pm;
|
||||||
|
pm = search_begin("sound/materials_*.txt", TRUE, TRUE);
|
||||||
|
for (int i = 0; i < search_getsize(pm); i++) {
|
||||||
|
HLMaterials_Load(search_getfilename(pm, i));
|
||||||
|
}
|
||||||
|
search_end(pm);
|
||||||
|
|
||||||
|
/* the way TW did it back in '03 */
|
||||||
|
HLMaterials_Load(sprintf("maps/%s.mat", mapname));
|
||||||
|
|
||||||
|
/* the way TW did it back in '03 */
|
||||||
|
HLMaterials_Load(sprintf("maps/%s_materials.txt", mapname));
|
||||||
|
}
|
|
@ -16,5 +16,6 @@ weapons.qc
|
||||||
vehicles.qc
|
vehicles.qc
|
||||||
modelevent.qc
|
modelevent.qc
|
||||||
mapcycle.qc
|
mapcycle.qc
|
||||||
|
hlmaterials.qc
|
||||||
entry.qc
|
entry.qc
|
||||||
#endlist
|
#endlist
|
||||||
|
|
Loading…
Reference in a new issue