- removed all remains of the old EAX editor.
This commit is contained in:
parent
1ed1b42c21
commit
57058ef727
7 changed files with 485 additions and 877 deletions
|
|
@ -3,7 +3,7 @@
|
|||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2005-2016 Randy Heit
|
||||
** Copyright 2005-2016 Christoph Oelckers
|
||||
** Copyright 2005-2017 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -41,7 +41,19 @@
|
|||
#include "w_wad.h"
|
||||
#include "i_system.h"
|
||||
|
||||
#include "c_cvars.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "files.h"
|
||||
#include "vm.h"
|
||||
#include "dobject.h"
|
||||
#include "menu/menu.h"
|
||||
|
||||
|
||||
|
||||
void InitReverbMenu();
|
||||
REVERB_PROPERTIES SavedProperties;
|
||||
ReverbContainer *CurrentEnv;
|
||||
extern ReverbContainer *ForcedEnvironment;
|
||||
|
||||
struct FReverbField
|
||||
{
|
||||
|
|
@ -51,6 +63,7 @@ struct FReverbField
|
|||
unsigned int Flag;
|
||||
};
|
||||
|
||||
|
||||
static const FReverbField ReverbFields[] =
|
||||
{
|
||||
{ 0, 25, 0, &REVERB_PROPERTIES::Environment, 0 },
|
||||
|
|
@ -656,3 +669,373 @@ void S_UnloadReverbDef ()
|
|||
}
|
||||
Environments = &Off;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, eaxedit_test, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
ForcedEnvironment = CurrentEnv;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForcedEnvironment = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
struct EnvFlag
|
||||
{
|
||||
const char *Name;
|
||||
int CheckboxControl;
|
||||
unsigned int Flag;
|
||||
};
|
||||
|
||||
inline int HIBYTE(int i)
|
||||
{
|
||||
return (i >> 8) & 255;
|
||||
}
|
||||
|
||||
inline int LOBYTE(int i)
|
||||
{
|
||||
return i & 255;
|
||||
}
|
||||
|
||||
uint16_t FirstFreeID(uint16_t base, bool builtin)
|
||||
{
|
||||
int tryCount = 0;
|
||||
int priID = HIBYTE(base);
|
||||
|
||||
// If the original sound is built-in, start searching for a new
|
||||
// primary ID at 30.
|
||||
if (builtin)
|
||||
{
|
||||
for (priID = 30; priID < 256; ++priID)
|
||||
{
|
||||
if (S_FindEnvironment(priID << 8) == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (priID == 256)
|
||||
{ // Oh well.
|
||||
priID = 30;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint16_t lastID = Environments->ID;
|
||||
const ReverbContainer *env = Environments->Next;
|
||||
|
||||
// Find the lowest-numbered free ID with the same primary ID as base
|
||||
// If none are available, add 100 to base's primary ID and try again.
|
||||
// If that fails, then the primary ID gets incremented
|
||||
// by 1 until a match is found. If all the IDs searchable by this
|
||||
// algorithm are in use, then you're in trouble.
|
||||
|
||||
while (env != nullptr)
|
||||
{
|
||||
if (HIBYTE(env->ID) > priID)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (HIBYTE(env->ID) == priID)
|
||||
{
|
||||
if (HIBYTE(lastID) == priID)
|
||||
{
|
||||
if (LOBYTE(env->ID) - LOBYTE(lastID) > 1)
|
||||
{
|
||||
return lastID + 1;
|
||||
}
|
||||
}
|
||||
lastID = env->ID;
|
||||
}
|
||||
env = env->Next;
|
||||
}
|
||||
if (LOBYTE(lastID) == 255)
|
||||
{
|
||||
if (tryCount == 0)
|
||||
{
|
||||
base += 100 * 256;
|
||||
tryCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
base += 256;
|
||||
}
|
||||
}
|
||||
else if (builtin && lastID == 0)
|
||||
{
|
||||
return priID << 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
return lastID + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FString SuggestNewName(const ReverbContainer *env)
|
||||
{
|
||||
const ReverbContainer *probe = nullptr;
|
||||
char text[32];
|
||||
size_t len;
|
||||
int number, numdigits;
|
||||
|
||||
strncpy(text, env->Name, 31);
|
||||
text[31] = 0;
|
||||
|
||||
len = strlen(text);
|
||||
while (text[len - 1] >= '0' && text[len - 1] <= '9')
|
||||
{
|
||||
len--;
|
||||
}
|
||||
number = atoi(text + len);
|
||||
if (number < 1)
|
||||
{
|
||||
number = 1;
|
||||
}
|
||||
|
||||
if (text[len - 1] != ' ' && len < 31)
|
||||
{
|
||||
text[len++] = ' ';
|
||||
}
|
||||
|
||||
for (; number < 100000; ++number)
|
||||
{
|
||||
if (number < 10) numdigits = 1;
|
||||
else if (number < 100) numdigits = 2;
|
||||
else if (number < 1000) numdigits = 3;
|
||||
else if (number < 10000)numdigits = 4;
|
||||
else numdigits = 5;
|
||||
if (len + numdigits > 31)
|
||||
{
|
||||
len = 31 - numdigits;
|
||||
}
|
||||
mysnprintf(text + len, countof(text) - len, "%d", number);
|
||||
|
||||
probe = Environments;
|
||||
while (probe != nullptr)
|
||||
{
|
||||
if (stricmp(probe->Name, text) == 0)
|
||||
break;
|
||||
probe = probe->Next;
|
||||
}
|
||||
if (probe == nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
void ExportEnvironments(const char *filename, uint32_t count, const ReverbContainer **envs)
|
||||
{
|
||||
FileWriter *f = FileWriter::Open("filename");
|
||||
|
||||
if (f != nullptr)
|
||||
{
|
||||
for (uint32_t i = 0; i < count; ++i)
|
||||
{
|
||||
const ReverbContainer *env = envs[i];
|
||||
const ReverbContainer *base;
|
||||
size_t j;
|
||||
|
||||
if ((unsigned int)env->Properties.Environment < 26)
|
||||
{
|
||||
base = DefaultEnvironments[env->Properties.Environment];
|
||||
}
|
||||
else
|
||||
{
|
||||
base = nullptr;
|
||||
}
|
||||
f->Printf("\"%s\" %u %u\n{\n", env->Name, HIBYTE(env->ID), LOBYTE(env->ID));
|
||||
for (j = 0; j < countof(ReverbFields); ++j)
|
||||
{
|
||||
const FReverbField *ctl = &ReverbFields[j];
|
||||
const char *ctlName = ReverbFieldNames[j];
|
||||
if (ctlName)
|
||||
{
|
||||
if (j == 0 ||
|
||||
(ctl->Float && base->Properties.*ctl->Float != env->Properties.*ctl->Float) ||
|
||||
(ctl->Int && base->Properties.*ctl->Int != env->Properties.*ctl->Int))
|
||||
{
|
||||
f->Printf("\t%s ", ctlName);
|
||||
if (ctl->Float)
|
||||
{
|
||||
float v = env->Properties.*ctl->Float * 1000;
|
||||
int vi = int(v >= 0.0 ? v + 0.5 : v - 0.5);
|
||||
f->Printf("%d.%03d\n", vi / 1000, abs(vi % 1000));
|
||||
}
|
||||
else
|
||||
{
|
||||
f->Printf("%d\n", env->Properties.*ctl->Int);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((1 << ctl->Flag) & (env->Properties.Flags ^ base->Properties.Flags))
|
||||
{
|
||||
f->Printf("\t%s %s\n", ctlName, ctl->Flag & env->Properties.Flags ? "true" : "false");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
f->Printf("}\n\n");
|
||||
}
|
||||
delete f;
|
||||
}
|
||||
else
|
||||
{
|
||||
M_StartMessage("Save failed", 1);
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DReverbEdit, GetValue)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(index);
|
||||
ACTION_RETURN_FLOAT(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DReverbEdit, SetValue)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(index);
|
||||
PARAM_FLOAT(value);
|
||||
ACTION_RETURN_FLOAT(value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DReverbEdit, GrayCheck)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
ACTION_RETURN_BOOL(CurrentEnv->Builtin);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DReverbEdit, GetSelectedEnvironment)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
if (numret > 1)
|
||||
{
|
||||
numret = 2;
|
||||
ret[1].SetInt(CurrentEnv ? CurrentEnv->ID : -1);
|
||||
}
|
||||
if (numret > 0)
|
||||
{
|
||||
ret[0].SetString(CurrentEnv ? CurrentEnv->Name : "");
|
||||
}
|
||||
return numret;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DReverbEdit, FillSelectMenu)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(ccmd);
|
||||
PARAM_OBJECT(desc, DOptionMenuDescriptor);
|
||||
desc->mItems.Clear();
|
||||
for (auto env = Environments; env != nullptr; env = env->Next)
|
||||
{
|
||||
FStringf text("(%d, %d) %s", HIBYTE(env->ID), LOBYTE(env->ID), env->Name);
|
||||
FStringf cmd("%s \"%s\"", ccmd.GetChars(), env->Name);
|
||||
PClass *cls = PClass::FindClass("OptionMenuItemCommand");
|
||||
if (cls != nullptr && cls->IsDescendantOf("OptionMenuItem"))
|
||||
{
|
||||
auto func = dyn_cast<PFunction>(cls->FindSymbol("Init", true));
|
||||
if (func != nullptr)
|
||||
{
|
||||
DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew();
|
||||
VMValue params[] = { item, &text, FName(cmd).GetIndex(), false, true };
|
||||
VMCall(func->Variants[0].Implementation, params, 5, nullptr, 0);
|
||||
desc->mItems.Push((DMenuItemBase*)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// These are for internal use only and not supposed to be user-settable
|
||||
CVAR(String, reverbedit_name, "", CVAR_NOSET);
|
||||
CVAR(Int, reverbedit_id1, 0, CVAR_NOSET);
|
||||
CVAR(Int, reverbedit_id2, 0, CVAR_NOSET);
|
||||
|
||||
static void SelectEnvironment(const char *envname)
|
||||
{
|
||||
for (auto env = Environments; env != nullptr; env = env->Next)
|
||||
{
|
||||
if (!strcmp(env->Name, envname))
|
||||
{
|
||||
CurrentEnv = env;
|
||||
SavedProperties = env->Properties;
|
||||
if (eaxedit_test) ForcedEnvironment = env;
|
||||
|
||||
// Set up defaults for a new environment based on this one.
|
||||
int newid = FirstFreeID(env->ID, env->Builtin);
|
||||
UCVarValue cv;
|
||||
cv.Int = HIBYTE(newid);
|
||||
reverbedit_id1.ForceSet(cv, CVAR_Int);
|
||||
cv.Int = LOBYTE(newid);
|
||||
reverbedit_id2.ForceSet(cv, CVAR_Int);
|
||||
FString selectname = SuggestNewName(env);
|
||||
cv.String = selectname.GetChars();
|
||||
reverbedit_name.ForceSet(cv, CVAR_String);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitReverbMenu()
|
||||
{
|
||||
// Make sure that the editor's variables are properly initialized.
|
||||
SelectEnvironment("Off");
|
||||
}
|
||||
|
||||
CCMD(selectenvironment)
|
||||
{
|
||||
if (argv.argc() > 1)
|
||||
{
|
||||
auto str = argv[1];
|
||||
SelectEnvironment(str);
|
||||
}
|
||||
else
|
||||
InitReverbMenu();
|
||||
}
|
||||
|
||||
CCMD(revertenvironment)
|
||||
{
|
||||
if (CurrentEnv != nullptr)
|
||||
{
|
||||
CurrentEnv->Properties = SavedProperties;
|
||||
}
|
||||
}
|
||||
|
||||
CCMD(createenvironment)
|
||||
{
|
||||
if (S_FindEnvironment(reverbedit_name))
|
||||
{
|
||||
M_StartMessage(FStringf("An environment with the name '%s' already exists", *reverbedit_name), 1);
|
||||
return;
|
||||
}
|
||||
int id = (reverbedit_id1 * 255) + reverbedit_id2;
|
||||
if (S_FindEnvironment(id))
|
||||
{
|
||||
M_StartMessage(FStringf("An environment with the ID (%d, %d) already exists", *reverbedit_id1, *reverbedit_id2), 1);
|
||||
return;
|
||||
}
|
||||
|
||||
auto newenv = new ReverbContainer;
|
||||
newenv->Builtin = false;
|
||||
newenv->ID = id;
|
||||
newenv->Name = copystring(reverbedit_name);
|
||||
newenv->Next = nullptr;
|
||||
newenv->Properties = CurrentEnv->Properties;
|
||||
S_AddEnvironment(newenv);
|
||||
SelectEnvironment(newenv->Name);
|
||||
}
|
||||
|
||||
CCMD(reverbedit)
|
||||
{
|
||||
C_DoCommand("openmenu reverbedit");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue