Merge C4DefCore and C4Def

The DefCore was only used by the editor and to get an id from a filename
for the drag and drop code. The former is dead, the latter does not need
the separation.
Günther Brammer 2009-05-20 00:34:13 +02:00
parent 79f8d5496a
commit 0898288a87
10 changed files with 28 additions and 48 deletions

View File

@ -90,7 +90,6 @@
#define C4CFN_DefGraphicsScaled "Graphics.*.bmp"
#define C4CFN_DefGraphicsScaledPNG "Graphics.*.png"
#define C4CFN_ClrByOwnerExPNG "Overlay*.png"
#define C4CFN_DefNames "Names%s.txt|Names.txt"
#define C4CFN_DefActMap "ActMap.txt"
#define C4CFN_DefDesc "Desc%s.txt"
#define C4CFN_BigIcon "BigIcon.png"

View File

@ -27,6 +27,7 @@
#include <C4Facet.h>
#include <C4Surface.h>
#include <C4ComponentHost.h>
#include <C4PropList.h>
#ifdef C4ENGINE
#include <C4ScriptHost.h>
@ -179,14 +180,11 @@ class C4ActionDef
void CompileFunc(StdCompiler *pComp);
};
class C4DefCore
class C4Def: public C4PropList
{
public:
C4DefCore();
public:
C4ID id;
int32_t rC4XVer[4];
StdCopyStrBuf Name;
C4IDList RequireDef;
C4PhysicalInfo Physical;
C4Shape Shape;
@ -271,19 +269,16 @@ class C4DefCore
int32_t AutoContextMenu; // automatically open context menu for this object
int32_t AllowPictureStack; // allow stacking of multiple items in menus even if some attributes do not match. APS_*-values
public:
void Default();
BOOL Load(C4Group &hGroup);
void DefaultDefCore();
BOOL LoadDefCore(C4Group &hGroup);
BOOL Save(C4Group &hGroup);
void CompileFunc(StdCompiler *pComp);
const char * GetName() const { return Name.getData(); }
protected:
BOOL Compile(const char *szSource, const char *szName);
BOOL Decompile(StdStrBuf *pOut, const char *szName);
};
class C4Def: public C4DefCore
{
// Here begins the C4Def
friend class C4DefList;
public:
C4Def();
@ -294,8 +289,7 @@ class C4Def: public C4DefCore
HBITMAP Picture;
HBITMAP Image;
#endif
int32_t ActNum; C4ActionDef *ActMap;
int32_t ActNum; C4ActionDef *ActMap;
char Maker[C4MaxName+1];
char Filename[_MAX_FNAME+1];
int32_t Creation;

View File

@ -26,7 +26,6 @@ class C4Playback;
class C4Scenario;
class C4PlayerInfoCore;
class C4ObjectInfoCore;
class C4DefCore;
class C4Def;
class C4DefList;
class C4IDList;

View File

@ -84,7 +84,7 @@ void C4AulScriptContext::dump(StdStrBuf Dump)
if(Obj)
Dump.AppendFormat(" (obj %s)", C4VObj(Obj).GetDataString().getData());
else if(Func->Owner->Def != NULL)
Dump.AppendFormat(" (def %s)", Func->Owner->Def->Name.getData());
Dump.AppendFormat(" (def %s)", Func->Owner->Def->GetName());
// Script
if(!fDirectExec && Func->Owner)
Dump.AppendFormat(" (%s:%d)",
@ -1012,7 +1012,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
FormatString("Object call: No function \"%s\" in object \"%s\"!", szFuncName, pTargetVal->GetDataString().getData()).getData());
else
throw new C4AulExecError(pCurCtx->Obj,
FormatString("Definition call: No function \"%s\" in definition \"%s\"!", szFuncName, pDestDef->Name.getData()).getData());
FormatString("Definition call: No function \"%s\" in definition \"%s\"!", szFuncName, pDestDef->GetName()).getData());
}
// Resolve overloads

View File

@ -135,16 +135,10 @@ void C4ActionDef::CompileFunc(StdCompiler *pComp)
//--------------------------------- C4DefCore ----------------------------------------------
C4DefCore::C4DefCore()
{
Default();
}
void C4DefCore::Default()
void C4Def::DefaultDefCore()
{
rC4XVer[0]=rC4XVer[1]=rC4XVer[2]=rC4XVer[3]=0;
RequireDef.Clear();
Name.Ref("Undefined");
Physical.Default();
Shape.Default();
Entrance.Default();
@ -223,7 +217,7 @@ void C4DefCore::Default()
NoTransferZones=0;
}
BOOL C4DefCore::Load(C4Group &hGroup)
BOOL C4Def::LoadDefCore(C4Group &hGroup)
{
StdStrBuf Source;
if (hGroup.LoadEntryString(C4CFN_DefCore,Source))
@ -268,7 +262,7 @@ BOOL C4DefCore::Load(C4Group &hGroup)
return FALSE;
}
BOOL C4DefCore::Save(C4Group &hGroup)
BOOL C4Def::Save(C4Group &hGroup)
{
StdStrBuf Out;
if (! Decompile(&Out, FormatString("%s::DefCore.txt", C4IdText(id)).getData()) )
@ -276,22 +270,22 @@ BOOL C4DefCore::Save(C4Group &hGroup)
return hGroup.Add(C4CFN_DefCore,Out,FALSE,TRUE);
}
BOOL C4DefCore::Compile(const char *szSource, const char *szName)
BOOL C4Def::Compile(const char *szSource, const char *szName)
{
return CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "DefCore"), StdStrBuf(szSource), szName);
}
BOOL C4DefCore::Decompile(StdStrBuf *pOut, const char *szName)
BOOL C4Def::Decompile(StdStrBuf *pOut, const char *szName)
{
return DecompileToBuf_Log<StdCompilerINIWrite>(mkNamingAdapt(*this, "DefCore"), pOut, szName);
}
void C4DefCore::CompileFunc(StdCompiler *pComp)
void C4Def::CompileFunc(StdCompiler *pComp)
{
pComp->Value(mkNamingAdapt(mkC4IDAdapt(id), "id", C4ID_None ));
pComp->Value(mkNamingAdapt(toC4CArr(rC4XVer), "Version" ));
pComp->Value(mkNamingAdapt(toC4CStrBuf(Name), "Name", "Undefined" ));
//FIXME pComp->Value(mkNamingAdapt(toC4CStrBuf(Name), "Name", "Undefined" ));
pComp->Value(mkNamingAdapt(mkParAdapt(RequireDef, false), "RequireDef", C4IDList() ));
const StdBitfieldEntry<int32_t> Categories[] = {
@ -416,7 +410,7 @@ void C4DefCore::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(mkBitfieldAdapt(GrabPutGet, GrabPutGetTypes),
"GrabPutGet", 0 ));
pComp->Value(mkNamingAdapt(Carryable, "Collectible", 0 ));
pComp->Value(mkNamingAdapt(Rotateable, "Rotate", 0 ));
pComp->Value(mkNamingAdapt(RotatedEntrance, "RotatedEntrance", 0 ));
@ -489,7 +483,7 @@ C4Def::C4Def()
void C4Def::Default()
{
C4DefCore::Default();
DefaultDefCore();
#if !defined(C4ENGINE) && !defined(C4GROUP)
Picture=NULL;
@ -596,14 +590,13 @@ BOOL C4Def::Load(C4Group &hGroup,
#endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Read DefCore
if (fSuccess) fSuccess=C4DefCore::Load(hGroup);
if (fSuccess) fSuccess=LoadDefCore(hGroup);
// check id
if (fSuccess) if (!LooksLikeID(id))
{
#ifdef C4ENGINE // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// wie geth ID?????ßßßß
if (!Name[0]) Name = GetFilename(hGroup.GetName());
LogF(LoadResStr("IDS_ERR_INVALIDID"), Name.getData());
LogF(LoadResStr("IDS_ERR_INVALIDID"), GetFilename(hGroup.GetName()));
#endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fSuccess=FALSE;
}
@ -703,15 +696,7 @@ BOOL C4Def::Load(C4Group &hGroup,
// for downwards compatibility with packing order
Script.Load("Script", hGroup, C4CFN_Script, szLanguage, this, &StringTable, true);
}
#endif
// Read name
C4ComponentHost DefNames;
if (DefNames.LoadEx("Names", hGroup, C4CFN_DefNames, szLanguage))
DefNames.GetLanguageString(szLanguage, Name);
DefNames.Close();
#ifdef C4ENGINE
// read clonknames
if (dwLoadWhat & C4D_Load_ClonkNames)
{
@ -813,7 +798,7 @@ BOOL C4Def::Load(C4Group &hGroup,
{
TopFace.Default();
// warn in debug mode
DebugLogF("invalid TopFace in %s(%s)", Name.getData(), C4IdText(id));
DebugLogF("invalid TopFace in %s(%s)", GetName(), C4IdText(id));
}

View File

@ -309,7 +309,7 @@ void C4DefGraphicsAdapt::CompileFunc(StdCompiler *pComp)
C4Def *pDef = Game.Defs.ID2Def(id);
// search def-graphics
if(!pDef || !( pDefGraphics = pDef->Graphics.Get(Name.getData()) ))
pComp->excCorrupt("DefGraphics: could not find graphics \"%s\" in %s(%s)!", Name.getData(), C4IdText(id), pDef ? pDef->Name.getData() : "def not found");
pComp->excCorrupt("DefGraphics: could not find graphics \"%s\" in %s(%s)!", Name.getData(), C4IdText(id), pDef ? pDef->GetName() : "def not found");
}
}

View File

@ -1538,9 +1538,9 @@ BOOL C4Game::CreateViewport(int32_t iPlayer, bool fSilent)
C4ID DefFileGetID(const char *szFilename)
{
C4Group hDef;
C4DefCore DefCore;
C4Def DefCore;
if (!hDef.Open(szFilename)) return C4ID_None;
if (!DefCore.Load(hDef)) { hDef.Close(); return C4ID_None; }
if (!DefCore.LoadDefCore(hDef)) { hDef.Close(); return C4ID_None; }
hDef.Close();
return DefCore.id;
}

View File

@ -160,6 +160,7 @@ BOOL C4Object::Init(C4Def *pDef, C4Object *pCreator,
LastEnergyLossCausePlayer=NO_OWNER;
Info=pInfo;
Def=pDef;
prototype = pDef;
if (Info) SetName(pInfo->Name);
Category=Def->Category;
Def->Count++;
@ -1238,6 +1239,7 @@ BOOL C4Object::ChangeDef(C4ID idNew)
Def->Count--;
// Def change
Def=pDef;
prototype = pDef;
id=pDef->id;
Def->Count++;
LocalNamed.SetNameList(&pDef->Script.LocalNamed);
@ -2648,6 +2650,7 @@ void C4Object::CompileFunc(StdCompiler *pComp)
if(fCompiler)
{
Def = Game.Defs.ID2Def(id);
prototype = Def;
if(!Def)
{ pComp->excNotFound(LoadResStr("IDS_PRC_UNDEFINEDOBJECT"),C4IdText(id)); return; }
}

View File

@ -1028,7 +1028,7 @@ static bool FnSetName(C4AulContext *cthr, C4String *pNewName, C4Object *pObj, C4
if (idDef)
if (pDef=C4Id2Def(idDef))
pDef->Name.Copy(FnStringPar(pNewName));
pDef->SetName(FnStringPar(pNewName));
else
return false;
else

View File

@ -671,7 +671,7 @@ void C4Shape::CreateOwnOriginalCopy(C4Shape &rFrom)
void C4Shape::CompileFunc(StdCompiler *pComp, bool fRuntime)
{
// Note: Compiled directly into "Object" and "DefCore"-categories, so beware of name clashes
// (see C4Object::CompileFunc and C4DefCore::CompileFunc)
// (see C4Object::CompileFunc and C4Def::CompileFunc)
pComp->Value(mkNamingAdapt( Wdt, "Width", 0 ));
pComp->Value(mkNamingAdapt( Hgt, "Height", 0 ));
pComp->Value(mkNamingAdapt( mkArrayAdapt(&x,2,0), "Offset" ));