📄 leveloptimizer.cpp
字号:
// LevelOptimizer.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include <windows.h>
#include "stdafx.h"
#include "..\Level.h"
#include "..\LevelPlus.h"
#include "..\Vectors.h"
#include "BCLLIST.h"
#define StandardFile "level.bcl"
char DaFile[80];
char TempSt[120];
struct tCLItem
{
tCommand *Command;
tCLItem *Next;
};
struct tOptSector
{
long ID;
tCLItem *Commands;
tOptSector *Next;
};
tSector *Level,*TempLevel;
tCommand *CommandList,*TempC;
tOptSector *IDList;
void OptimizeCACommand(tCommand *Temp,tSector *Sector)
{
tCommand_Change_Attributes *Old;
tCommand_Change_Attributes_Opt *New;
New=(tCommand_Change_Attributes_Opt*)malloc(sizeof(tCommand_Change_Attributes_Opt));
Old=(tCommand_Change_Attributes*)Temp->Data;
unsigned char Content;
Content=0;
if(Sector->OrgPos.X!=Old->Pos.X) Content=SetFlag(Content,1);
if(Sector->OrgPos.Y!=Old->Pos.Y) Content=SetFlag(Content,2);
if(Sector->OrgPos.Z!=Old->Pos.Z) Content=SetFlag(Content,4);
if(Sector->Size.X!=Old->Size.X) Content=SetFlag(Content,8);
if(Sector->Size.Y!=Old->Size.Y) Content=SetFlag(Content,16);
if(Sector->Size.Z!=Old->Size.Z) Content=SetFlag(Content,32);
if(Sector->SizeMul!=Old->SizeMul) Content=SetFlag(Content,64);
if((Old->Nr>=0)&&(Old->Nr<=255)) Content|=128;
New->Content=Content;
New->Nr=Old->Nr;
New->Pos=Old->Pos;
New->Size=Old->Size;
New->SizeMul=Old->SizeMul;
Temp->Data=New;
Temp->Type=_Command_Change_Attributes_Opt;
}
void OptimizeMVCommand(tCommand *Temp)
{
tCommand_Move_Vertice_With_Radius *Old;
tCommand_Move_Vertice_With_Radius_Opt *New;
New=(tCommand_Move_Vertice_With_Radius_Opt*)malloc(sizeof(tCommand_Move_Vertice_With_Radius_Opt));
Old=(tCommand_Move_Vertice_With_Radius*)Temp->Data;
New->Radius=Old->Radius;
New->SNr=Old->SNr;
New->SubDivs=Old->SubDivs;
New->Vek=Old->Vek;
New->VNr=Old->VNr;
Temp->Data=New;
Temp->Type=_Command_Move_Vertice_With_Radius_Opt;
}
void OptimizeCICommand(tCommand *Temp)
{
tCommand_CreateItem *Old;
tCommand_CreateItem_Opt *New;
New=(tCommand_CreateItem_Opt*)malloc(sizeof(tCommand_CreateItem_Opt));
Old=(tCommand_CreateItem*)Temp->Data;
New->Attr=Old->Attr;
New->Flags=Old->Flags;
New->Pos=Old->Pos;
Temp->Data=New;
Temp->Type=_Command_CreateItem_Opt;
}
void OptimizeCubeCommand(tCommand *Temp)
{
tCommand_Create_Cube *Old;
tCommand_Create_Cube_Opt *New;
float F;
New=(tCommand_Create_Cube_Opt*)malloc(sizeof(tCommand_Create_Cube_Opt));
Old=(tCommand_Create_Cube*)Temp->Data;
F=Old->EckAmount*255.0;
New->EckAmount=F;
New->PartsI=Old->PartsI;
Temp->Data=New;
Temp->Type=_Command_Cube_Opt;
}
void OptimizeMatCommand(tCommand *Temp)
{
tCommand_Set_Material *Old;
tCommand_Set_Material_Opt *New;
New=(tCommand_Set_Material_Opt*)malloc(sizeof(tCommand_Set_Material_Opt));
Old=(tCommand_Set_Material*)Temp->Data;
New->Material=Old->Material;
New->Par1=Old->Par1;
New->Par2=Old->Par2;
New->SNr=Old->SNr;
New->TexType=Old->TexType;
Temp->Data=New;
Temp->Type=_Command_Set_Material_Opt;
}
void OptimizeFlagCommand(tCommand *Temp)
{
tCommand_ChangeFlags *Old;
tCommand_ChangeFlags_Opt *New;
New=(tCommand_ChangeFlags_Opt*)malloc(sizeof(tCommand_ChangeFlags_Opt));
Old=(tCommand_ChangeFlags*)Temp->Data;
New->Attr=Old->Attr;
New->Flags=Old->Flags;
New->SNr=Old->SNr;
Temp->Data=New;
Temp->Type=_Command_ChangeFlags_Opt;
}
void OptimizeRotCommand(tCommand *Temp)
{
tCommand_Rotate *Old;
tCommand_Rotate_Opt *New;
float F;
New=(tCommand_Rotate_Opt*)malloc(sizeof(tCommand_Rotate_Opt));
Old=(tCommand_Rotate*)Temp->Data;
New->SNr=Old->SNr;
New->Amount=Old->Amount;
New->Dir=Old->Dir;
/*
New->SNr=Old->SNr;
F=Old->Amount;
while(F<0) F=F+360.0;
while(F>=360.0) F=F-360.0;
F=F*30.0;
New->Amount=F;
if(Old->Dir==1) New->Amount|=32768;
if(Old->Dir==2) New->Amount|=16384;
*/
Temp->Data=New;
Temp->Type=_Command_Rotate_Opt;
}
void OptimizeMakeSubCommand(tCommand *Temp)
{
tCommand_Make_Sub *Old;
tCommand_Make_Sub2 *New;
float F;
Old=(tCommand_Make_Sub*)Temp->Data;
if((Old->FNr>=0)&&(Old->FNr<=255)&&(Old->SNr>=0)&&(Old->SNr<=255))
{
New=(tCommand_Make_Sub2*)malloc(sizeof(tCommand_Make_Sub2));
New->FNr=Old->FNr;
New->SNr=Old->SNr;
Temp->Data=New;
Temp->Type=_Command_Make_Sub2;
}
}
void OptimizeCloneCommand(tCommand *Temp)
{
tCommand_Clone *Old;
tCommand_Clone2 *New;
float F;
Old=(tCommand_Clone*)Temp->Data;
if((Old->SNr>=0)&&(Old->SNr<=255))
{
New=(tCommand_Clone2*)malloc(sizeof(tCommand_Clone2));
New->SNr=Old->SNr;
Temp->Data=New;
Temp->Type=_Command_Clone2;
}
}
void OptimizeInsCommand(tCommand *Temp)
{
tCommand_InsertLevel *Old;
tCommand_InsertOpt *New;
char MyChar[20];
char *P1,*P2;
long I;
New=(tCommand_InsertOpt*)malloc(sizeof(tCommand_InsertOpt));
Old=(tCommand_InsertLevel*)Temp->Data;
P1=(char*) &Old->FName;
P2=(char*) &MyChar;
I=0;
while((I<9)&&(*(P1+I)!='.'))
{
*(P2+I)=*(P1+I);
I++;
}
*(MyChar+I)='.';I++;
*(MyChar+I)='b';I++;
*(MyChar+I)='c';I++;
*(MyChar+I)='l';I++;
*(MyChar+I)=0;
New->Nr=GetBCLNr(MyChar);
Temp->Data=New;
Temp->Type=_Command_Insert_Opt;
}
bool NextCommand(tCommand *Command,long Type)
{
if(Command==NULL) return(false);
if(Command->Next==NULL) return(false);
if(Command->Next->Type==Type) return(true);
return(false);
}
bool Next2Commands(tCommand *Command,long Type1,long Type2)
{
if(!NextCommand(Command,Type1)) return(false);
if(!NextCommand(Command->Next,Type2)) return(false);
return(true);
}
bool OptimizeAttRotAtt(tCommand *C)
{
tCommand_Change_Attributes *Old,*New;
tCommand_Rotate *Rot;
Old=(tCommand_Change_Attributes*)C->Data;
Rot=(tCommand_Rotate*)C->Next->Data;
New=(tCommand_Change_Attributes*)C->Next->Next->Data;
if((Old->Nr==New->Nr)&&(Old->Nr==Rot->SNr))
{
C->Type=C->Next->Type;
C->Data=C->Next->Data;
C->Next=C->Next->Next;
return(true);
} else { return(false); }
}
int main(int argc, char* argv[])
{
tCommand_Change_Attributes *CA;
tSector *TempS;
long I;
vNull=vSet(0,0,0);
CreateMaterials();
if(argc<=1)
{
strcpy(DaFile,StandardFile);
} else {
strcpy(DaFile,argv[1]);
}
printf("Loading ");
printf(DaFile);
printf("\n");
CommandList=LoadLevel(DaFile);
printf("Has %d Commands \n",CountCommandList(CommandList));
GlobalSector=NULL;
Level=CreateSector();
GlobalSector=Level;
TempC=CommandList;
while(TempC!=NULL)
{
if((TempC->Type==_Command_Change_Attributes)&&
Next2Commands(TempC,_Command_Rotate,_Command_Change_Attributes) )
{
CA=(tCommand_Change_Attributes*)TempC->Data;
TempS=GetSubSectorNr(Level,CA->Nr);
if(vEqual(TempS->Size,CA->Size))
OptimizeAttRotAtt(TempC);
}
if(TempC->Type==_Command_Change_Attributes)
{
CA=(tCommand_Change_Attributes*)TempC->Data;
TempS=GetSubSectorNr(Level,CA->Nr);
OptimizeCACommand(TempC,TempS);
}
if(TempC->Type==_Command_Move_Vertice_With_Radius)
{
OptimizeMVCommand(TempC);
}
if(TempC->Type==_Command_Cube)
{
OptimizeCubeCommand(TempC);
}
if(TempC->Type==_Command_Rotate)
{
OptimizeRotCommand(TempC);
}
if(TempC->Type==_Command_Make_Sub)
{
OptimizeMakeSubCommand(TempC);
}
if(TempC->Type==_Command_Clone)
{
OptimizeCloneCommand(TempC);
}
if(TempC->Type==_Command_CreateItem)
{
OptimizeCICommand(TempC);
}
if(TempC->Type==_Command_Set_Material)
{
OptimizeMatCommand(TempC);
}
if(TempC->Type==_Command_ChangeFlags)
{
OptimizeFlagCommand(TempC);
}
CalcCommand(TempC,Level);
if(TempC->Type==_Command_InsertLevel)
{
OptimizeInsCommand(TempC);
}
TempC=TempC->Next;
}
printf("Optimized successfully !\n");
printf("Saving ...");
strcpy(TempSt,"../BCLOPD3D/");
strcat(TempSt,DaFile);
SaveLevel(TempSt,CommandList);
printf("Complete\n");
/*
printf("Scanning ID's\n");
IDList=CalcIDList(Level);
GlobalSector=NULL;
TempLevel=CreateSector();
GlobalSector=TempLevel;
TempC=CommandList;
while(TempC!=NULL)
{
CalcCommand(TempC,TempLevel);
TempC=TempC->Next;
}
*/
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -