2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
|
|
|
* Copyright (c) 2009-2013, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
/* string table: holds all strings used by script engine */
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4StringTable.h>
|
|
|
|
|
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
// *** C4Set
|
|
|
|
template<> template<>
|
2012-07-25 23:21:15 +00:00
|
|
|
unsigned int C4Set<C4String *>::Hash<const char *>(const char * const & s)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
// Fowler/Noll/Vo hash
|
|
|
|
unsigned int h = 2166136261u;
|
2012-07-25 23:21:15 +00:00
|
|
|
const char * p = s;
|
|
|
|
while (*p)
|
|
|
|
h = (h ^ *(p++)) * 16777619;
|
2009-04-01 21:36:58 +00:00
|
|
|
return h;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
template<> template<>
|
2012-07-25 23:21:15 +00:00
|
|
|
bool C4Set<C4String *>::Equals<const char *>(C4String * const & a, const char * const & b)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
return a->GetData() == b;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
// *** C4String
|
|
|
|
|
|
|
|
C4String::C4String(StdStrBuf strString)
|
2010-12-08 22:27:02 +00:00
|
|
|
: RefCnt(0)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// take string
|
2009-11-25 18:38:54 +00:00
|
|
|
Data.Take(std::move(strString));
|
2010-12-06 15:24:41 +00:00
|
|
|
Hash = Strings.Set.Hash(Data.getData());
|
2009-05-08 13:28:41 +00:00
|
|
|
// reg
|
2009-04-03 21:53:48 +00:00
|
|
|
Strings.Set.Add(this);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-12-06 15:24:41 +00:00
|
|
|
C4String::C4String()
|
2010-12-08 22:27:02 +00:00
|
|
|
: RefCnt(0)
|
2010-12-06 15:24:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
C4String::~C4String()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// unreg
|
2010-12-08 22:27:02 +00:00
|
|
|
static bool remove = false;
|
|
|
|
assert(!remove);
|
|
|
|
remove = true;
|
2009-04-03 21:53:48 +00:00
|
|
|
Strings.Set.Remove(this);
|
2010-12-08 22:27:02 +00:00
|
|
|
remove = false;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-12-06 15:24:41 +00:00
|
|
|
void C4String::operator=(const char * s)
|
|
|
|
{
|
2010-12-08 22:27:02 +00:00
|
|
|
assert(!RefCnt);
|
2010-12-06 15:24:41 +00:00
|
|
|
assert(!Data);
|
|
|
|
// ref string
|
|
|
|
Data.Ref(s);
|
|
|
|
Hash = Strings.Set.Hash(Data.getData());
|
|
|
|
// reg
|
|
|
|
Strings.Set.Add(this);
|
|
|
|
}
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
// *** C4StringTable
|
|
|
|
|
|
|
|
C4StringTable::C4StringTable()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-06 15:24:41 +00:00
|
|
|
P[P_Prototype] = "Prototype";
|
|
|
|
P[P_Name] = "Name";
|
2010-12-24 14:10:39 +00:00
|
|
|
P[P_Priority] = "Priority";
|
|
|
|
P[P_Interval] = "Interval";
|
|
|
|
P[P_CommandTarget] = "CommandTarget";
|
|
|
|
P[P_Time] = "Time";
|
2010-12-06 15:24:41 +00:00
|
|
|
P[P_Collectible] = "Collectible";
|
2011-01-02 22:55:48 +00:00
|
|
|
P[P_Touchable] = "Touchable";
|
2010-12-06 15:24:41 +00:00
|
|
|
P[P_ActMap] = "ActMap";
|
|
|
|
P[P_Procedure] = "Procedure";
|
2010-12-11 20:10:05 +00:00
|
|
|
P[P_Speed] = "Speed";
|
|
|
|
P[P_Accel] = "Accel";
|
|
|
|
P[P_Decel] = "Decel";
|
2010-12-06 15:24:41 +00:00
|
|
|
P[P_Attach] = "Attach";
|
|
|
|
P[P_Directions] = "Directions";
|
|
|
|
P[P_FlipDir] = "FlipDir";
|
|
|
|
P[P_Length] = "Length";
|
|
|
|
P[P_Delay] = "Delay";
|
|
|
|
P[P_X] = "X";
|
|
|
|
P[P_Y] = "Y";
|
|
|
|
P[P_Wdt] = "Wdt";
|
|
|
|
P[P_Hgt] = "Hgt";
|
|
|
|
P[P_OffX] = "OffX";
|
|
|
|
P[P_OffY] = "OffY";
|
|
|
|
P[P_FacetBase] = "FacetBase";
|
|
|
|
P[P_FacetTopFace] = "FacetTopFace";
|
|
|
|
P[P_FacetTargetStretch] = "FacetTargetStretch";
|
|
|
|
P[P_NextAction] = "NextAction";
|
|
|
|
P[P_Hold] = "Hold";
|
|
|
|
P[P_Idle] = "Idle";
|
|
|
|
P[P_NoOtherAction] = "NoOtherAction";
|
|
|
|
P[P_StartCall] = "StartCall";
|
|
|
|
P[P_EndCall] = "EndCall";
|
|
|
|
P[P_AbortCall] = "AbortCall";
|
|
|
|
P[P_PhaseCall] = "PhaseCall";
|
|
|
|
P[P_Sound] = "Sound";
|
|
|
|
P[P_ObjectDisabled] = "ObjectDisabled";
|
|
|
|
P[P_DigFree] = "DigFree";
|
|
|
|
P[P_InLiquidAction] = "InLiquidAction";
|
|
|
|
P[P_TurnAction] = "TurnAction";
|
|
|
|
P[P_Reverse] = "Reverse";
|
|
|
|
P[P_Step] = "Step";
|
|
|
|
P[P_Animation] = "Animation";
|
|
|
|
P[P_Action] = "Action";
|
|
|
|
P[P_Visibility] = "Visibility";
|
|
|
|
P[P_Parallaxity] = "Parallaxity";
|
|
|
|
P[P_LineColors] = "LineColors";
|
|
|
|
P[P_LineAttach] = "LineAttach";
|
2013-05-09 10:02:44 +00:00
|
|
|
P[P_LineMaxDistance] = "LineMaxDistance";
|
2011-12-28 18:33:19 +00:00
|
|
|
P[P_MouseDrag] = "MouseDrag";
|
2010-12-06 15:24:41 +00:00
|
|
|
P[P_MouseDragImage] = "MouseDragImage";
|
|
|
|
P[P_PictureTransformation] = "PictureTransformation";
|
|
|
|
P[P_MeshTransformation] = "MeshTransformation";
|
2010-12-12 20:49:47 +00:00
|
|
|
P[P_BreatheWater] = "BreatheWater";
|
|
|
|
P[P_CorrosionResist] = "CorrosionResist";
|
2010-12-12 21:38:15 +00:00
|
|
|
P[P_MaxEnergy] = "MaxEnergy";
|
2010-12-12 22:01:08 +00:00
|
|
|
P[P_MaxBreath] = "MaxBreath";
|
2010-12-13 01:17:21 +00:00
|
|
|
P[P_ThrowSpeed] = "ThrowSpeed";
|
2010-12-21 20:57:40 +00:00
|
|
|
P[P_Mode] = "Mode";
|
|
|
|
P[P_CausedBy] = "CausedBy";
|
|
|
|
P[P_Blasted] = "Blasted";
|
|
|
|
P[P_IncineratingObj] = "IncineratingObj";
|
2010-12-27 19:15:55 +00:00
|
|
|
P[P_Plane] = "Plane";
|
2012-04-15 10:09:54 +00:00
|
|
|
P[P_Tooltip] = "Tooltip";
|
2012-04-16 20:17:05 +00:00
|
|
|
P[P_Placement] = "Placement";
|
2012-04-28 14:17:38 +00:00
|
|
|
P[P_BlastIncinerate] = "BlastIncinerate";
|
|
|
|
P[P_ContactIncinerate] = "ContactIncinerate";
|
2012-08-19 20:43:32 +00:00
|
|
|
P[P_Global] = "Global";
|
2013-03-22 21:56:02 +00:00
|
|
|
P[P_Scenario] = "Scenario";
|
2012-12-09 17:42:52 +00:00
|
|
|
P[P_JumpSpeed] = "JumpSpeed";
|
2013-03-18 23:35:00 +00:00
|
|
|
P[P_Algo] = "Algo";
|
|
|
|
P[P_Layer] = "Layer";
|
|
|
|
P[P_Seed] = "Seed";
|
|
|
|
P[P_Ratio] = "Ratio";
|
|
|
|
P[P_FixedOffset] = "FixedOffset";
|
|
|
|
P[P_Op] = "Op";
|
|
|
|
P[P_R] = "R";
|
|
|
|
P[P_Scale] = "Scale";
|
|
|
|
P[P_Amplitude] = "Amplitude";
|
|
|
|
P[P_Iterations] = "Iterations";
|
|
|
|
P[P_Empty] = "Empty";
|
|
|
|
P[P_Open] = "Open";
|
|
|
|
P[P_Left] = "Left";
|
|
|
|
P[P_Top] = "Top";
|
|
|
|
P[P_Right] = "Right";
|
|
|
|
P[P_Bottom] = "Bottom";
|
|
|
|
P[P_Filter] = "Filter";
|
2013-09-21 14:48:28 +00:00
|
|
|
P[P_ForceX] = "ForceX";
|
|
|
|
P[P_ForceY] = "ForceY";
|
|
|
|
P[P_G] = "G";
|
|
|
|
P[P_B] = "B";
|
|
|
|
P[P_Alpha] = "Alpha";
|
|
|
|
P[P_DampingX] = "DampingX";
|
|
|
|
P[P_DampingY] = "DampingY";
|
|
|
|
P[P_Size] = "Size";
|
2013-09-24 18:36:49 +00:00
|
|
|
P[P_Rotation] = "Rotation";
|
2013-09-24 19:15:24 +00:00
|
|
|
P[P_BlitMode] = "BlitMode";
|
2013-09-25 11:30:06 +00:00
|
|
|
P[P_Phase] = "Phase";
|
2013-09-27 11:28:38 +00:00
|
|
|
P[P_Stretch] = "Stretch";
|
2013-09-27 13:27:53 +00:00
|
|
|
P[P_CollisionVertex] = "CollisionVertex";
|
2013-09-27 14:06:25 +00:00
|
|
|
P[P_OnCollision] = "OnCollision";
|
2013-10-12 17:28:22 +00:00
|
|
|
P[P_Distance] = "Distance";
|
2013-12-14 11:09:31 +00:00
|
|
|
P[P_Smoke] = "Smoke";
|
2010-12-08 22:17:00 +00:00
|
|
|
P[DFA_WALK] = "WALK";
|
|
|
|
P[DFA_FLIGHT] = "FLIGHT";
|
|
|
|
P[DFA_KNEEL] = "KNEEL";
|
|
|
|
P[DFA_SCALE] = "SCALE";
|
|
|
|
P[DFA_HANGLE] = "HANGLE";
|
|
|
|
P[DFA_DIG] = "DIG";
|
|
|
|
P[DFA_SWIM] = "SWIM";
|
|
|
|
P[DFA_THROW] = "THROW";
|
|
|
|
P[DFA_BRIDGE] = "BRIDGE";
|
|
|
|
P[DFA_PUSH] = "PUSH";
|
|
|
|
P[DFA_LIFT] = "LIFT";
|
|
|
|
P[DFA_FLOAT] = "FLOAT";
|
|
|
|
P[DFA_ATTACH] = "ATTACH";
|
|
|
|
P[DFA_CONNECT] = "CONNECT";
|
|
|
|
P[DFA_PULL] = "PULL";
|
2010-12-06 15:24:41 +00:00
|
|
|
// Prevent the individual strings from being deleted, they are not created with new
|
|
|
|
for (unsigned int i = 0; i < P_LAST; ++i) P[i].IncRef();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4StringTable::~C4StringTable()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2010-12-16 23:31:51 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
if(Set.GetSize() != P_LAST)
|
|
|
|
{
|
|
|
|
for (C4String * const * s = Set.First(); s; s = Set.Next(s))
|
|
|
|
{
|
2011-02-25 17:11:54 +00:00
|
|
|
if (*s >= &Strings.P[0] && *s < &Strings.P[P_LAST])
|
2013-03-18 23:29:20 +00:00
|
|
|
{
|
|
|
|
if ((*s)->RefCnt != 1)
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugString(FormatString(" \"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt).GetWideChar());
|
|
|
|
#else
|
|
|
|
fprintf(stderr, " \"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt);
|
|
|
|
#endif
|
|
|
|
}
|
2011-02-25 17:11:54 +00:00
|
|
|
else
|
2013-03-18 23:29:20 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugString(FormatString("\"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt).GetWideChar());
|
|
|
|
#else
|
2012-02-02 00:16:14 +00:00
|
|
|
fprintf(stderr, "\"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt);
|
2013-03-18 23:29:20 +00:00
|
|
|
#endif
|
2010-12-16 23:31:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-12-06 15:24:41 +00:00
|
|
|
assert(Set.GetSize() == P_LAST);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String *C4StringTable::RegString(StdStrBuf String)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
C4String * s = FindString(String.getData());
|
|
|
|
if (s)
|
|
|
|
return s;
|
|
|
|
else
|
2009-04-01 21:36:58 +00:00
|
|
|
return new C4String(String);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String *C4StringTable::FindString(const char *strString)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
return Set.Get(strString);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|