void asCBuilder::ParseScripts() { asCArray<asCParser*> parsers; // Parse all the files as if they were one asUINT n = 0; for( n = 0; n < scripts.GetLength(); n++ ) { asCParser *parser = new asCParser(this); parsers.PushLast(parser); // Parse the script file parser->ParseScript(scripts[n]); } if( numErrors == 0 ) { // Find all type declarations for( n = 0; n < scripts.GetLength(); n++ ) { asCScriptNode *node = parsers[n]->GetScriptNode(); // Find structure definitions first node = node->firstChild; while( node ) { asCScriptNode *next = node->next; if( node->nodeType == snClass ) { node->DisconnectParent(); RegisterClass(node, scripts[n]); } else if( node->nodeType == snInterface ) { node->DisconnectParent(); RegisterInterface(node, scripts[n]); } node = next; } } // Register script methods found in the structures for( n = 0; n < classDeclarations.GetLength(); n++ ) { sClassDeclaration *decl = classDeclarations[n]; asCScriptNode *node = decl->node->firstChild->next; // Skip list of classes and interfaces while( node && node->nodeType == snIdentifier ) node = node->next; while( node ) { asCScriptNode *next = node->next; if( node->nodeType == snFunction ) { node->DisconnectParent(); RegisterScriptFunction(module->GetNextFunctionId(), node, decl->script, decl->objType); } node = next; } // Make sure the default constructor exists for classes if( decl->objType->beh.construct == engine->scriptTypeBehaviours.beh.construct ) { AddDefaultConstructor(decl->objType, decl->script); } } // Register script methods found in the interfaces for( n = 0; n < interfaceDeclarations.GetLength(); n++ ) { sClassDeclaration *decl = interfaceDeclarations[n]; asCScriptNode *node = decl->node->firstChild->next; while( node ) { asCScriptNode *next = node->next; if( node->nodeType == snFunction ) { node->DisconnectParent(); RegisterScriptFunction(module->GetNextFunctionId(), node, decl->script, decl->objType, true); } node = next; } } // Find other global nodes for( n = 0; n < scripts.GetLength(); n++ ) { // Find other global nodes asCScriptNode *node = parsers[n]->GetScriptNode(); node = node->firstChild; while( node ) { asCScriptNode *next = node->next; node->DisconnectParent(); if( node->nodeType == snFunction ) { RegisterScriptFunction(module->GetNextFunctionId(), node, scripts[n]); } else if( node->nodeType == snGlobalVar ) { RegisterGlobalVar(node, scripts[n]); } else if( node->nodeType == snImport ) { RegisterImportedFunction(module->GetNextImportedFunctionId(), node, scripts[n]); } else { // Unused script node int r, c; scripts[n]->ConvertPosToRowCol(node->tokenPos, &r, &c); WriteWarning(scripts[n]->name.AddressOf(), TXT_UNUSED_SCRIPT_NODE, r, c); delete node; } node = next; } } } for( n = 0; n < parsers.GetLength(); n++ ) delete parsers[n]; }
void ScriptInterpreter::setupScriptFunctions() { // 0 RegisterScriptFunction(sfNop); RegisterScriptFunction(sfNop); RegisterScriptFunction(sfGetGameVar); RegisterScriptFunction(sfSetGameVar); RegisterScriptFunction(sfUpdateScreen); // 5 RegisterScriptFunction(sfGetRandomNumber); RegisterScriptFunction(sfDrawGuiTextMulti); RegisterScriptFunction(sfUpdateVerbLine); RegisterScriptFunction(sfSetFontColor); RegisterScriptFunction(sfGetTalkTextDuration); // 10 RegisterScriptFunction(sfTalk); RegisterScriptFunction(sfFindPaletteFragment); RegisterScriptFunction(sfClearPaletteFragments); RegisterScriptFunction(sfAddPaletteFragment); RegisterScriptFunction(sfSetDeltaAnimPalette); // 15 RegisterScriptFunction(sfSetUnkPaletteEffect); RegisterScriptFunction(sfBuildColorTransTable); RegisterScriptFunction(sfSetDeltaMainPalette); RegisterScriptFunction(sfLoadScript); RegisterScriptFunction(sfRegisterFont); // 20 RegisterScriptFunction(sfLoadAddPalette); RegisterScriptFunction(sfLoadScene); RegisterScriptFunction(sfSetGuiHeight); RegisterScriptFunction(sfFindMouseInRectIndex1); RegisterScriptFunction(sfFindMouseInRectIndex2); // 25 RegisterScriptFunction(sfDrawGuiImage); RegisterScriptFunction(sfAddAnimatedSpriteNoLoop); RegisterScriptFunction(sfAddAnimatedSprite); RegisterScriptFunction(sfAddStaticSprite); RegisterScriptFunction(sfAddAnimatedSpriteScaled); // 30 RegisterScriptFunction(sfFindPath); RegisterScriptFunction(sfWalk); RegisterScriptFunction(sfScrollCameraUp); RegisterScriptFunction(sfScrollCameraDown); RegisterScriptFunction(sfScrollCameraLeft); // 35 RegisterScriptFunction(sfScrollCameraRight); RegisterScriptFunction(sfScrollCameraUpEx); RegisterScriptFunction(sfScrollCameraDownEx); RegisterScriptFunction(sfScrollCameraLeftEx); RegisterScriptFunction(sfScrollCameraRightEx); // 40 RegisterScriptFunction(sfSetCamera); RegisterScriptFunction(sfGetCameraChanged); RegisterScriptFunction(sfGetRgbModifiertAtPoint); RegisterScriptFunction(sfStartAnim); RegisterScriptFunction(sfAnimNextFrame); // 45 RegisterScriptFunction(sfNop); RegisterScriptFunction(sfGetAnimFrameNumber); RegisterScriptFunction(sfGetAnimStatus); RegisterScriptFunction(sfStartShakeScreen); RegisterScriptFunction(sfStopShakeScreen); // 50 RegisterScriptFunction(sfStartSequence); RegisterScriptFunction(sfEndSequence); RegisterScriptFunction(sfSetSequenceVolume); RegisterScriptFunction(sfPlayPositionalSound); RegisterScriptFunction(sfPlaySound2); // 55 RegisterScriptFunction(sfClearScreen); RegisterScriptFunction(sfNop); RegisterScriptFunction(sfHandleInput); RegisterScriptFunction(sfRunOptionsScreen); RegisterScriptFunction(sfPrecacheSprites); // 60 RegisterScriptFunction(sfPrecacheSounds1); RegisterScriptFunction(sfDeletePrecachedFiles); RegisterScriptFunction(sfPrecacheSounds2); RegisterScriptFunction(sfRestoreStackPtr); RegisterScriptFunction(sfSaveStackPtr); // 65 RegisterScriptFunction(sfPlayMovie); RegisterScriptFunction(sfNop); }
void asCBuilder::ParseScripts() { asCArray<asCParser*> parsers; // Parse all the files as if they were one asUINT n = 0; for( n = 0; n < scripts.GetLength(); n++ ) { asCParser *parser = new asCParser(this); parsers.PushLast(parser); // Parse the script file parser->ParseScript(scripts[n]); } if( numErrors == 0 ) { // Find all type declarations for( n = 0; n < scripts.GetLength(); n++ ) { asCScriptNode *node = parsers[n]->GetScriptNode(); // Find structure definitions first node = node->firstChild; while( node ) { asCScriptNode *next = node->next; if( node->nodeType == snStruct ) { node->DisconnectParent(); RegisterStruct(node, scripts[n]); } node = next; } } // Find other global nodes for( n = 0; n < scripts.GetLength(); n++ ) { // Find other global nodes asCScriptNode *node = parsers[n]->GetScriptNode(); node = node->firstChild; while( node ) { asCScriptNode *next = node->next; node->DisconnectParent(); if( node->nodeType == snFunction ) { RegisterScriptFunction(module->GetNextFunctionId(), node, scripts[n]); } else if( node->nodeType == snGlobalVar ) { RegisterGlobalVar(node, scripts[n]); } else if( node->nodeType == snImport ) { RegisterImportedFunction(module->GetNextImportedFunctionId(), node, scripts[n]); } else { // Unused script node int r, c; scripts[n]->ConvertPosToRowCol(node->tokenPos, &r, &c); WriteWarning(scripts[n]->name.AddressOf(), TXT_UNUSED_SCRIPT_NODE, r, c); delete node; } node = next; } } } for( n = 0; n < parsers.GetLength(); n++ ) delete parsers[n]; }