Skip to content

Commit e03cd30

Browse files
authored
Finished yesterday's compiler versioning work.
I'm not sure I *like* it yet, but I think it'll *work*, at least, and my C++ knowledge is too limited to make it any better.
1 parent 9222035 commit e03cd30

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

source/game/scripts/bind_general.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const unsigned _UINT_MAX = UINT_MAX;
4545
const float _F_INFINITY = std::numeric_limits<float>::infinity();
4646
const double _D_INFINITY = std::numeric_limits<double>::infinity();
4747
const std::string _BUILD_NAME(BUILD_VERSION);
48+
const unsigned _OSR_COMPILER_VERSION = OSR_COMPILER_VERSION;
4849
#ifdef NSTEAM
4950
const bool isSteamBuild = false;
5051
#else
@@ -895,6 +896,7 @@ void RegisterGeneralBinds(bool server, bool shadow) {
895896
bindGlobal("float FLOAT_INFINITY", (void*)&_F_INFINITY);
896897
bindGlobal("const string BUILD_VERSION", (void*)&_BUILD_NAME);
897898
bindGlobal("const bool IS_STEAM_BUILD", (void*)&isSteamBuild);
899+
bindGlobal("const uint OSR_COMPILER_VERSION", (void*)&_OSR_COMPILER_VERSION)
898900

899901
//Engine detection
900902
if(server) {

source/game/scripts/binds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "network/message.h"
77
#include <map>
88

9+
#define OSR_COMPILER_VERSION 1
10+
911
struct Player;
1012
struct Image;
1113
class Object;

source/game/scripts/manager.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868

6969
#define DISABLE_SCRIPT_CACHE
7070

71-
#define OSR_COMPILER_VERSION 1
72-
7371
namespace scripts {
7472
extern void RegisterEarlyNetworkBinds(asIScriptEngine* engine);
7573

@@ -414,7 +412,9 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
414412

415413

416414
for(auto iLine = lines.begin(), end = lines.end(); iLine != end; ++iLine) {
417-
const std::string& line = *iLine;
415+
const std::string& originalLine = *iLine;
416+
// I'm not actually sure if this amounts to a meaningful optimization... or any optimization.
417+
std:string& line = originalLine;
418418

419419
auto lineStart = line.find_first_not_of(" \t");
420420
if(lineStart == std::string::npos) {
@@ -488,12 +488,26 @@ void parseFile(Manager* man, File& fl, const std::string& filename, bool cacheFi
488488

489489
// TODO: Figure out something a little better-optimized than always running
490490
// three regexes on every line of code?
491+
// On the bright side, we're only running them if we're in the right section...
491492
if(reg_match(line, match, pre_osr_single_line)) {
492493
const std::string prefix = reg_str(line, match, 1);
493494
const std::string postfix = reg_str(line, match, 4);
494-
// TODO: Actually evaluate this bit here. The goal is to replace line with prefix+postfix if the spec matches.
495495
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
496-
496+
line = prefix + postfix;
497+
}
498+
}
499+
if(reg_match(line, match, pre_osr_multi_open)) {
500+
const std::string prefix = reg_str(line, match, 1);
501+
const std::string postfix = reg_str(line, match, 4);
502+
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
503+
line = prefix + postfix;
504+
}
505+
}
506+
if(reg_match(line, match, pre_osr_multi_close)) {
507+
const std::string prefix = reg_str(line, match, 1);
508+
const std::string postfix = reg_str(line, match, 4);
509+
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
510+
line = prefix + postfix;
497511
}
498512
}
499513

0 commit comments

Comments
 (0)