AGS: Move cc_script.cpp globals to Globals

This commit is contained in:
Paul Gilbert 2021-03-06 20:07:09 -08:00
parent dfbcfd212c
commit 1e327a63f8
9 changed files with 31 additions and 29 deletions

View file

@ -104,7 +104,7 @@ int32_t ccGetObjectHandleFromAddress(const char *address) {
int32_t handl = _GP(pool).AddressToHandle(address); int32_t handl = _GP(pool).AddressToHandle(address);
ManagedObjectLog("Line %d WritePtr: %08X to %d", currentline, address, handl); ManagedObjectLog("Line %d WritePtr: %08X to %d", _G(currentline), address, handl);
if (handl == 0) { if (handl == 0) {
cc_error("Pointer cast failure: the object being pointed to is not in the managed object pool"); cc_error("Pointer cast failure: the object being pointed to is not in the managed object pool");
@ -119,7 +119,7 @@ const char *ccGetObjectAddressFromHandle(int32_t handle) {
} }
const char *addr = _GP(pool).HandleToAddress(handle); const char *addr = _GP(pool).HandleToAddress(handle);
ManagedObjectLog("Line %d ReadPtr: %d to %08X", currentline, handle, addr); ManagedObjectLog("Line %d ReadPtr: %d to %08X", _G(currentline), handle, addr);
if (addr == nullptr) { if (addr == nullptr) {
cc_error("Error retrieving pointer: invalid handle %d", handle); cc_error("Error retrieving pointer: invalid handle %d", handle);

View file

@ -56,7 +56,7 @@ int ManagedObjectPool::Remove(ManagedObject &o, bool force) {
handleByAddress.erase(o.addr); handleByAddress.erase(o.addr);
o = ManagedObject(); o = ManagedObject();
ManagedObjectLog("Line %d Disposed managed object handle=%d", currentline, handle); ManagedObjectLog("Line %d Disposed managed object handle=%d", _G(currentline), handle);
return 1; return 1;
} }
@ -71,7 +71,7 @@ int32_t ManagedObjectPool::AddRef(int32_t handle) {
} }
o.refCount += 1; o.refCount += 1;
ManagedObjectLog("Line %d AddRef: handle=%d new refcount=%d", currentline, o.handle, o.refCount); ManagedObjectLog("Line %d AddRef: handle=%d new refcount=%d", _G(currentline), o.handle, o.refCount);
return o.refCount; return o.refCount;
} }
@ -105,7 +105,7 @@ int32_t ManagedObjectPool::SubRef(int32_t handle) {
CheckDispose(handle); CheckDispose(handle);
} }
// object could be removed at this point, don't use any values. // object could be removed at this point, don't use any values.
ManagedObjectLog("Line %d SubRef: handle=%d new refcount=%d canBeDisposed=%d", currentline, handle, newRefCount, canBeDisposed); ManagedObjectLog("Line %d SubRef: handle=%d new refcount=%d canBeDisposed=%d", _G(currentline), handle, newRefCount, canBeDisposed);
return newRefCount; return newRefCount;
} }

View file

@ -282,7 +282,7 @@ void debug_script_print(const String &msg, MessageType mt) {
scriptname = "D "; scriptname = "D ";
else else
scriptname = "? "; scriptname = "? ";
script_ref.Format("[%s%d]", scriptname.GetCStr(), currentline); script_ref.Format("[%s%d]", scriptname.GetCStr(), _G(currentline));
} }
Debug::Printf(kDbgGroup_Game, mt, "(room:%d)%s %s", displayed_room, script_ref.GetCStr(), msg.GetCStr()); Debug::Printf(kDbgGroup_Game, mt, "(room:%d)%s %s", displayed_room, script_ref.GetCStr(), msg.GetCStr());

View file

@ -277,7 +277,7 @@ void ccInstance::AbortAndDestroy() {
int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const RuntimeScriptValue *params) { int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const RuntimeScriptValue *params) {
_G(ccError) = 0; _G(ccError) = 0;
currentline = 0; _G(currentline) = 0;
if (numargs > 0 && !params) { if (numargs > 0 && !params) {
cc_error("internal error in ccInstance::CallScriptFunction"); cc_error("internal error in ccInstance::CallScriptFunction");
@ -402,7 +402,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
} \ } \
callStackSize--;\ callStackSize--;\
line_number = callStackLineNumber[callStackSize];\ line_number = callStackLineNumber[callStackSize];\
currentline = line_number _G(currentline) = line_number
#define MAXNEST 50 // number of recursive function calls allowed #define MAXNEST 50 // number of recursive function calls allowed
int ccInstance::Run(int32_t curpc) { int ccInstance::Run(int32_t curpc) {
@ -531,9 +531,9 @@ int ccInstance::Run(int32_t curpc) {
switch (codeOp.Instruction.Code) { switch (codeOp.Instruction.Code) {
case SCMD_LINENUM: case SCMD_LINENUM:
line_number = arg1.IValue; line_number = arg1.IValue;
currentline = arg1.IValue; _G(currentline) = arg1.IValue;
if (new_line_hook) if (new_line_hook)
new_line_hook(this, currentline); new_line_hook(this, _G(currentline));
break; break;
case SCMD_ADD: case SCMD_ADD:
// If the the register is SREG_SP, we are allocating new variable on the stack // If the the register is SREG_SP, we are allocating new variable on the stack
@ -1288,7 +1288,7 @@ bool ccInstance::IsBeingRun() const {
bool ccInstance::_Create(PScript scri, ccInstance *joined) { bool ccInstance::_Create(PScript scri, ccInstance *joined) {
int i; int i;
currentline = -1; _G(currentline) = -1;
if ((scri == nullptr) && (joined != nullptr)) if ((scri == nullptr) && (joined != nullptr))
scri = joined->instanceof; scri = joined->instanceof;

View file

@ -35,6 +35,7 @@
#include "ags/shared/script/cc_error.h" #include "ags/shared/script/cc_error.h"
#include "ags/shared/util/file.h" #include "ags/shared/util/file.h"
#include "ags/shared/util/stream.h" #include "ags/shared/util/stream.h"
#include "ags/globals.h"
namespace AGS3 { namespace AGS3 {
@ -47,12 +48,11 @@ class RoomStruct;
using namespace AGS::Shared; using namespace AGS::Shared;
extern void quit(const char *); extern void quit(const char *);
extern int currentline; // in script/script_common
std::pair<String, String> cc_error_at_line(const char *error_msg) { std::pair<String, String> cc_error_at_line(const char *error_msg) {
ccInstance *sci = ccInstance::GetCurrentInstance(); ccInstance *sci = ccInstance::GetCurrentInstance();
if (!sci) { if (!sci) {
return std::make_pair(String::FromFormat("Error (line %d): %s", currentline, error_msg), String()); return std::make_pair(String::FromFormat("Error (line %d): %s", _G(currentline), error_msg), String());
} else { } else {
return std::make_pair(String::FromFormat("Error: %s\n", error_msg), ccInstance::GetCurrentInstance()->GetCallStack(5)); return std::make_pair(String::FromFormat("Error: %s\n", error_msg), ccInstance::GetCurrentInstance()->GetCallStack(5));
} }

View file

@ -164,6 +164,18 @@ public:
/**@}*/ /**@}*/
/**
* \defgroup cc_script globals
* @{
*/
// currently executed line
int _currentline = 0;
// script file format signature
const char _scfilesig[5] = "SCOM";
/**@}*/
/** /**
* \defgroup debug globals * \defgroup debug globals
* @{ * @{

View file

@ -46,7 +46,7 @@ void cc_error(const char *descr, ...) {
String displbuf = String::FromFormatV(descr, ap); String displbuf = String::FromFormatV(descr, ap);
va_end(ap); va_end(ap);
if (currentline > 0) { if (_G(currentline) > 0) {
// [IKM] Implementation is project-specific // [IKM] Implementation is project-specific
std::pair<String, String> errinfo = cc_error_at_line(displbuf); std::pair<String, String> errinfo = cc_error_at_line(displbuf);
_G(ccErrorString) = errinfo.first; _G(ccErrorString) = errinfo.first;
@ -57,7 +57,7 @@ void cc_error(const char *descr, ...) {
} }
_G(ccError) = 1; _G(ccError) = 1;
_G(ccErrorLine) = currentline; _G(ccErrorLine) = _G(currentline);
} }
} // namespace AGS3 } // namespace AGS3

View file

@ -25,16 +25,12 @@
#include "ags/shared/script/script_common.h" #include "ags/shared/script/script_common.h"
#include "ags/shared/util/stream.h" #include "ags/shared/util/stream.h"
#include "ags/shared/util/string_compat.h" #include "ags/shared/util/string_compat.h"
#include "ags/globals.h"
namespace AGS3 { namespace AGS3 {
using AGS::Shared::Stream; using AGS::Shared::Stream;
// currently executed line
int currentline;
// script file format signature
const char scfilesig[5] = "SCOM";
// [IKM] I reckon this function is almost identical to fgetstring in string_utils // [IKM] I reckon this function is almost identical to fgetstring in string_utils
void freadstring(char **strptr, Stream *in) { void freadstring(char **strptr, Stream *in) {
static char ibuffer[300]; static char ibuffer[300];
@ -177,7 +173,7 @@ ccScript::~ccScript() {
void ccScript::Write(Shared::Stream *out) { void ccScript::Write(Shared::Stream *out) {
int n; int n;
out->Write(scfilesig, 4); out->Write(_G(scfilesig), 4);
out->WriteInt32(SCOM_VERSION); out->WriteInt32(SCOM_VERSION);
out->WriteInt32(globaldatasize); out->WriteInt32(globaldatasize);
out->WriteInt32(codesize); out->WriteInt32(codesize);
@ -213,14 +209,14 @@ bool ccScript::Read(Shared::Stream *in) {
instances = 0; instances = 0;
int n; int n;
char gotsig[5]; char gotsig[5];
currentline = -1; _G(currentline) = -1;
// MACPORT FIX: swap 'size' and 'nmemb' // MACPORT FIX: swap 'size' and 'nmemb'
in->Read(gotsig, 4); in->Read(gotsig, 4);
gotsig[4] = 0; gotsig[4] = 0;
int fileVer = in->ReadInt32(); int fileVer = in->ReadInt32();
if ((strcmp(gotsig, scfilesig) != 0) || (fileVer > SCOM_VERSION)) { if ((strcmp(gotsig, _G(scfilesig)) != 0) || (fileVer > SCOM_VERSION)) {
cc_error("file was not written by ccScript::Write or seek position is incorrect"); cc_error("file was not written by ccScript::Write or seek position is incorrect");
return false; return false;
} }

View file

@ -132,12 +132,6 @@ namespace AGS3 {
#define FIXUP_DATADATA 5 // globaldata[fixup] += &globaldata[0] #define FIXUP_DATADATA 5 // globaldata[fixup] += &globaldata[0]
#define FIXUP_STACK 6 // code[fixup] += &stack[0] #define FIXUP_STACK 6 // code[fixup] += &stack[0]
extern int currentline;
// Script file signature
extern const char scfilesig[5];
#define ENDFILESIG 0xbeefcafe #define ENDFILESIG 0xbeefcafe
} // namespace AGS3 } // namespace AGS3