Skip to content

Commit

Permalink
Finished yesterday's compiler versioning work.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaloLorn authored Jan 28, 2025
1 parent 9222035 commit e03cd30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions source/game/scripts/bind_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const unsigned _UINT_MAX = UINT_MAX;
const float _F_INFINITY = std::numeric_limits<float>::infinity();
const double _D_INFINITY = std::numeric_limits<double>::infinity();
const std::string _BUILD_NAME(BUILD_VERSION);
const unsigned _OSR_COMPILER_VERSION = OSR_COMPILER_VERSION;
#ifdef NSTEAM
const bool isSteamBuild = false;
#else
Expand Down Expand Up @@ -895,6 +896,7 @@ void RegisterGeneralBinds(bool server, bool shadow) {
bindGlobal("float FLOAT_INFINITY", (void*)&_F_INFINITY);
bindGlobal("const string BUILD_VERSION", (void*)&_BUILD_NAME);
bindGlobal("const bool IS_STEAM_BUILD", (void*)&isSteamBuild);
bindGlobal("const uint OSR_COMPILER_VERSION", (void*)&_OSR_COMPILER_VERSION)

//Engine detection
if(server) {
Expand Down
2 changes: 2 additions & 0 deletions source/game/scripts/binds.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "network/message.h"
#include <map>

#define OSR_COMPILER_VERSION 1

struct Player;
struct Image;
class Object;
Expand Down
24 changes: 19 additions & 5 deletions source/game/scripts/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@

#define DISABLE_SCRIPT_CACHE

#define OSR_COMPILER_VERSION 1

namespace scripts {
extern void RegisterEarlyNetworkBinds(asIScriptEngine* engine);

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


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

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

// TODO: Figure out something a little better-optimized than always running
// three regexes on every line of code?
// On the bright side, we're only running them if we're in the right section...
if(reg_match(line, match, pre_osr_single_line)) {
const std::string prefix = reg_str(line, match, 1);
const std::string postfix = reg_str(line, match, 4);
// TODO: Actually evaluate this bit here. The goal is to replace line with prefix+postfix if the spec matches.
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {

line = prefix + postfix;
}
}
if(reg_match(line, match, pre_osr_multi_open)) {
const std::string prefix = reg_str(line, match, 1);
const std::string postfix = reg_str(line, match, 4);
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
line = prefix + postfix;
}
}
if(reg_match(line, match, pre_osr_multi_close)) {
const std::string prefix = reg_str(line, match, 1);
const std::string postfix = reg_str(line, match, 4);
if(matchesCompilerVersion(reg_str(line, match, 2), reg_str(line, match, 3))) {
line = prefix + postfix;
}
}

Expand Down

1 comment on commit e03cd30

@DaloLorn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gaaah, I forgot to prefix it with [#10] for tracking. 😭

Please sign in to comment.