2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2002, 2005 Peter Wortmann
|
|
|
|
* Copyright (c) 2006, 2009 Günther Brammer
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or 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.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
/* string table: holds all strings used by script engine */
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4StringTable.h>
|
|
|
|
|
|
|
|
#include <C4Group.h>
|
|
|
|
#include <C4Components.h>
|
2009-04-03 21:53:48 +00:00
|
|
|
//#include <C4Aul.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
// *** C4Set
|
|
|
|
template<> template<>
|
|
|
|
unsigned int C4Set<C4String *>::Hash<const char *>(const char * 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;
|
|
|
|
while (*s)
|
|
|
|
h = (h ^ *(s++)) * 16777619;
|
|
|
|
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<>
|
|
|
|
bool C4Set<C4String *>::Equals<const char *>(C4String * a, const char * 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";
|
|
|
|
P[P_Collectible] = "Collectible";
|
|
|
|
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_EnergyUsage] = "EnergyUsage";
|
|
|
|
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";
|
|
|
|
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-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_BUILD] = "BUILD";
|
|
|
|
P[DFA_PUSH] = "PUSH";
|
|
|
|
P[DFA_CHOP] = "CHOP";
|
|
|
|
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-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
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-03 21:53:48 +00:00
|
|
|
C4StringTable Strings;
|