mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +00:00
- added the entry point for the ZScript compiler.
This commit is contained in:
parent
d4cdb31464
commit
edd9f1773b
3 changed files with 108 additions and 0 deletions
|
@ -800,6 +800,7 @@ set (PCH_SOURCES
|
|||
core/raze_music.cpp
|
||||
core/raze_sound.cpp
|
||||
core/palette.cpp
|
||||
core/zcompile.cpp
|
||||
|
||||
core/2d/screentext.cpp
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "i_interface.h"
|
||||
#include "x86.h"
|
||||
#include "startupinfo.h"
|
||||
#include "mapinfo.h"
|
||||
#include "menustate.h"
|
||||
|
||||
CVAR(Bool, autoloadlights, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR(Bool, autoloadbrightmaps, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
|
@ -117,6 +119,7 @@ void InitENet();
|
|||
void ShutdownENet();
|
||||
void S_ParseSndInfo();
|
||||
void I_DetectOS(void);
|
||||
void LoadScripts();
|
||||
|
||||
|
||||
bool AppActive;
|
||||
|
@ -546,6 +549,7 @@ int GameMain()
|
|||
}
|
||||
InitENet();
|
||||
DeleteStartupScreen();
|
||||
PClass::StaticShutdown();
|
||||
if (Args) delete Args;
|
||||
return r;
|
||||
}
|
||||
|
@ -836,6 +840,7 @@ int RunGame()
|
|||
timerSetCallback(Mus_UpdateMusic);
|
||||
S_ParseSndInfo();
|
||||
InitStatistics();
|
||||
LoadScripts();
|
||||
M_Init();
|
||||
SetDefaultStrings();
|
||||
if (g_gameType & (GAMEFLAG_RR)) InitRREndMap(); // this needs to be done better later
|
||||
|
|
102
source/core/zcompile.cpp
Normal file
102
source/core/zcompile.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
** zcompile.cpp
|
||||
**
|
||||
** Entry point for the script compiler
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2016-2020 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "filesystem.h"
|
||||
#include "sc_man.h"
|
||||
#include "zcc_parser.h"
|
||||
#include "zcc_compile.h"
|
||||
#include "codegen.h"
|
||||
#include "stats.h"
|
||||
#include "printf.h"
|
||||
#include "dobject.h"
|
||||
|
||||
void InitImports();
|
||||
|
||||
void ParseScripts()
|
||||
{
|
||||
int lump, lastlump = 0;
|
||||
FScriptPosition::ResetErrorCounter();
|
||||
|
||||
while ((lump = fileSystem.FindLump("ZSCRIPT", &lastlump)) != -1)
|
||||
{
|
||||
ZCCParseState state;
|
||||
auto newns = ParseOneScript(lump, state);
|
||||
PSymbolTable symtable;
|
||||
|
||||
ZCCCompiler cc(state, NULL, symtable, newns, lump, state.ParseVersion);
|
||||
cc.Compile();
|
||||
|
||||
if (FScriptPosition::ErrorCounter > 0)
|
||||
{
|
||||
// Abort if the compiler produced any errors. Also do not compile further lumps, because they very likely miss some stuff.
|
||||
I_Error("%d errors, %d warnings while compiling %s", FScriptPosition::ErrorCounter, FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).GetChars());
|
||||
}
|
||||
else if (FScriptPosition::WarnCounter > 0)
|
||||
{
|
||||
// If we got warnings, but no errors, print the information but continue.
|
||||
Printf(TEXTCOLOR_ORANGE "%d warnings while compiling %s\n", FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).GetChars());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LoadScripts()
|
||||
{
|
||||
cycle_t timer;
|
||||
|
||||
PClass::StaticInit();
|
||||
PType::StaticInit();
|
||||
InitImports();
|
||||
timer.Reset(); timer.Clock();
|
||||
FScriptPosition::ResetErrorCounter();
|
||||
|
||||
FScriptPosition::StrictErrors = true;
|
||||
ParseScripts();
|
||||
|
||||
FunctionBuildList.Build();
|
||||
|
||||
if (FScriptPosition::ErrorCounter > 0)
|
||||
{
|
||||
I_Error("%d errors during script processing", FScriptPosition::ErrorCounter);
|
||||
}
|
||||
FScriptPosition::ResetErrorCounter();
|
||||
|
||||
timer.Unclock();
|
||||
if (!batchrun) Printf("script parsing took %.2f ms\n", timer.TimeMS());
|
||||
|
||||
// Now we may call the scripted OnDestroy method.
|
||||
PClass::bVMOperational = true;
|
||||
}
|
Loading…
Reference in a new issue