Permalink
Browse files

Merge pull request #1448 from enigma-dev/GameData

Migrate compiler to a GameData structure. This is a big change for the compiler, and barring any regressions, is a massively-positive one. This change has undergone a lot of testing to try to weed out any regressions, but it's impossible to be certain right now. Time will tell, and I believe any further regressions should be simple enough to patch.
  • Loading branch information...
JoshDreamland committed Jan 19, 2019
2 parents ca38f27 + 990f744 commit a1aa34d57d91e438bf937a39d902a6556932eaec
Showing with 1,737 additions and 1,386 deletions.
  1. +2 −2 .gitignore
  2. +1 −1 CommandLine/emake/Makefile
  3. +17 −15 CommandLine/emake/Proto2ES.cpp
  4. +1 −1 CommandLine/libEGM/CMakeLists.txt
  5. +1 −1 CommandLine/libEGM/Makefile
  6. +1 −1 CommandLine/libEGM/egm-rooms.cpp
  7. +27 −15 CommandLine/libEGM/gmk.cpp
  8. +4 −2 CompilerSource/Makefile
  9. +2 −0 CompilerSource/backend/EnigmaStruct.h
  10. +422 −0 CompilerSource/backend/GameData.cpp
  11. +145 −0 CompilerSource/backend/GameData.h
  12. +145 −237 CompilerSource/compiler/compile.cpp
  13. +0 −6 CompilerSource/compiler/compile_common.h
  14. +7 −6 CompilerSource/compiler/compile_organization.h
  15. +0 −108 CompilerSource/compiler/components/handle_templates.cpp
  16. +20 −20 CompilerSource/compiler/components/module_write_backgrounds.cpp
  17. +32 −48 CompilerSource/compiler/components/module_write_fonts.cpp
  18. +14 −14 CompilerSource/compiler/components/module_write_paths.cpp
  19. +15 −15 CompilerSource/compiler/components/module_write_sounds.cpp
  20. +27 −25 CompilerSource/compiler/components/module_write_sprites.cpp
  21. +202 −206 CompilerSource/compiler/components/parse_and_link.cpp
  22. +31 −32 CompilerSource/compiler/components/parse_secondary.cpp
  23. +51 −34 CompilerSource/compiler/components/write_defragged_events.cpp
  24. +14 −16 CompilerSource/compiler/components/write_font_info.cpp
  25. +45 −35 CompilerSource/compiler/components/write_globals.cpp
  26. +7 −10 CompilerSource/compiler/components/write_object_access.cpp
  27. +141 −138 CompilerSource/compiler/components/write_object_data.cpp
  28. +116 −111 CompilerSource/compiler/components/write_room_data.cpp
  29. +8 −9 CompilerSource/compiler/components/write_shader_data.cpp
  30. +1 −1 CompilerSource/compiler/jdi_utility.cpp
  31. +38 −38 CompilerSource/languages/lang_CPP.cpp
  32. +23 −28 CompilerSource/languages/lang_CPP.h
  33. +21 −23 CompilerSource/languages/language_adapter.h
  34. +19 −67 CompilerSource/parser/object_storage.cpp
  35. +59 −25 CompilerSource/parser/object_storage.h
  36. +6 −6 CompilerSource/parser/parser.cpp
  37. +1 −1 CompilerSource/parser/parser.h
  38. +2 −1 CompilerSource/parser/parser_components.cpp
  39. +1 −42 CompilerSource/settings-parse/crawler.cpp
  40. +2 −6 CompilerSource/settings-parse/crawler.h
  41. +11 −12 CompilerSource/settings-parse/parse_ide_settings.cpp
  42. +2 −1 CompilerSource/syntax/syntax.cpp
  43. +4 −4 Makefile
  44. 0 {CommandLine → shared}/protos/Background.proto
  45. 0 {CommandLine → shared}/protos/Building.md
  46. 0 {CommandLine → shared}/protos/CMakeLists.txt
  47. 0 {CommandLine → shared}/protos/Event.proto
  48. +9 −4 {CommandLine → shared}/protos/Font.proto
  49. 0 {CommandLine → shared}/protos/GameInformation.proto
  50. 0 {CommandLine → shared}/protos/Include.proto
  51. 0 {CommandLine → shared}/protos/Makefile
  52. 0 {CommandLine → shared}/protos/Object.proto
  53. 0 {CommandLine → shared}/protos/Path.proto
  54. +13 −9 {CommandLine → shared}/protos/Room.proto
  55. 0 {CommandLine → shared}/protos/Script.proto
  56. +25 −9 {CommandLine → shared}/protos/Settings.proto
  57. 0 {CommandLine → shared}/protos/Shader.proto
  58. 0 {CommandLine → shared}/protos/Sound.proto
  59. 0 {CommandLine → shared}/protos/Sprite.proto
  60. +2 −1 {CommandLine → shared}/protos/Timeline.proto
  61. 0 {CommandLine → shared}/protos/game.proto
  62. 0 {CommandLine → shared}/protos/options.proto
  63. 0 {CommandLine → shared}/protos/project.proto
  64. 0 {CommandLine → shared}/protos/server.proto
  65. 0 {CommandLine → shared}/protos/treenode.proto
@@ -11,9 +11,9 @@
/libProtocols.*


/shared/protos/build/
/shared/protos/codegen
/CommandLine/libEGM/build/
/CommandLine/protos/build/
/CommandLine/protos/codegen

/ENIGMAsystem/SHELL/API_Switchboard.h
/ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/
@@ -16,7 +16,7 @@ else
OS_LIBS=-lboost_system-mt -Wl,--no-as-needed -Wl,-rpath=./ -lboost_program_options-mt -lboost_iostreams-mt -lboost_filesystem-mt -lboost_system-mt -lpthread
endif

PROTO_DIR := ../protos
PROTO_DIR := ../../shared/protos
CXXFLAGS := -I$(SRC_DIR) -I../../CompilerSource -I../../shared -I$(PROTO_DIR) -I$(PROTO_DIR)/codegen -I$(SHARED_SRC_DIR)/lodepng -std=c++11 -Wall -Wextra -Wpedantic -g
LDFLAGS := $(OS_LIBS) -L../../ -lz -L$(SHARED_SRC_DIR)/lodepng -llodepng -lProtocols -lprotobuf

@@ -556,11 +556,10 @@ void AddTimeline(const char* name, buffers::resources::Timeline* tml) {
t.moments = new Moment[t.momentCount];
for (int i = 0; i < t.momentCount; ++i) {
buffers::resources::Timeline::Moment* mmt = tml->mutable_moments(i);
buffers::resources::Event* evt = mmt->mutable_event();
t.moments[i].stepNo = mmt->step();
if (evt->actions_size() > 0)
evt->set_code(Actions2Code(evt->actions()));
t.moments[i].code = evt->code().c_str();
if (mmt->actions_size() > 0)
mmt->set_code(Actions2Code(mmt->actions()));
t.moments[i].code = mmt->code().c_str();
}
}
}
@@ -624,7 +623,7 @@ void AddRoom(const char* name, const buffers::resources::Room& rm) {
r.persistent = rm.persistent();
r.backgroundColor = BGR2RGBA(rm.color());
r.drawBackgroundColor = rm.show_color();
r.creationCode = rm.code().c_str();
r.creationCode = rm.creation_code().c_str();
r.enableViews = rm.enable_views();

r.backgroundDefCount = rm.backgrounds_size();
@@ -668,7 +667,7 @@ Instance AddInstance(const buffers::resources::Room::Instance& inst) {
i.x = inst.x();
i.y = inst.y();
i.locked = inst.editor_settings().locked();
i.creationCode = inst.code().c_str();
i.creationCode = inst.creation_code().c_str();
i.preCreationCode = "";

return i;
@@ -739,7 +738,6 @@ void WriteSettings(GameSettings &gs, const buffers::resources::Settings& set) {
// General
const buffers::resources::General &gen = set.general();
gs.gameId = gen.game_id();
gs.colorOutsideRoom = gen.color_outside_room_region();
gs.versionMajor = gen.version_major();
gs.versionMinor = gen.version_minor();
gs.versionRelease = gen.version_release();
@@ -753,17 +751,21 @@ void WriteSettings(GameSettings &gs, const buffers::resources::Settings& set) {

// Graphics
const buffers::resources::Graphics &gfx = set.graphics();
gs.startFullscreen = gfx.start_in_fullscreen();
gs.colorOutsideRoom = gfx.color_outside_room_region();
gs.letF4SwitchFullscreen = gfx.allow_fullscreen_change();
gs.interpolate = gfx.smooth_colors();
gs.interpolate = gfx.interpolate_textures();
gs.forceSoftwareVertexProcessing = gfx.force_software_vertex_processing();
gs.freezeOnLoseFocus = gfx.freeze_on_lose_focus();
gs.useSynchronization = gfx.use_synchronization();
gs.allowWindowResize = gfx.window_sizeable();
gs.dontDrawBorder = !gfx.window_showborder();
gs.dontShowButtons = !gfx.window_showicons();
gs.alwaysOnTop = gfx.window_stayontop();
gs.scaling = gfx.window_scale();
gs.scaling = gfx.view_scale();

// Windowing
const buffers::resources::Windowing &win = set.windowing();
gs.startFullscreen = win.start_in_fullscreen();
gs.freezeOnLoseFocus = win.freeze_on_lose_focus();
gs.allowWindowResize = win.is_sizeable();
gs.dontDrawBorder = !win.show_border();
gs.dontShowButtons = !win.show_icons();
gs.alwaysOnTop = win.stay_on_top();

// Project Info
const buffers::resources::Info &inf = set.info();
@@ -53,7 +53,7 @@ endif(MSVC)
find_package(yaml-cpp CONFIG REQUIRED)
target_link_libraries(${LIB} PRIVATE yaml-cpp)

include_directories(. "${ENIGMA_DIR}/CommandLine/protos/" "${ENIGMA_DIR}/shared/lodepng")
include_directories(. "${ENIGMA_DIR}/shared/protos/" "${ENIGMA_DIR}/shared/lodepng")

include(FindProtobuf)
target_link_libraries(${LIB} PRIVATE ${Protobuf_LIBRARY})
@@ -10,7 +10,7 @@ endif
GCCVER := $(shell gcc -dumpversion | cut -c 1)
SHARED_SOURCES := ../../shared
LIBRARY := ../../libEGM$(EXT)
PROTO_DIR := ../protos
PROTO_DIR := ../../shared/protos
SRC_DIR := .
OBJ_DIR := .eobjs

@@ -628,7 +628,7 @@ Room::Instance StripForLump(const Room::Instance &inst) {
Room::Instance::EditorSettings::default_instance())) {
res.clear_editor_settings();
}
if (res.code().empty()) res.clear_code();
if (res.creation_code().empty()) res.clear_creation_code();

// DO NOT SUBMIT: this should be an option or otherwise not exist
res.clear_id();
@@ -455,22 +455,23 @@ int LoadSettings(Decoder &dec, Settings& set) {

General* gen = set.mutable_general();
Graphics* gfx = set.mutable_graphics();
Windowing *win = set.mutable_windowing();
Info* inf = set.mutable_info();

if (ver >= 800) dec.beginInflate();
gfx->set_start_in_fullscreen(dec.readBool());
win->set_start_in_fullscreen(dec.readBool());
if (ver >= 600) {
gfx->set_smooth_colors(dec.readBool());
gfx->set_interpolate_textures(dec.readBool());
}
gfx->set_window_showborder(!dec.readBool()); // inverted because negative in GM (e.g, "don't")
win->set_show_border(!dec.readBool()); // inverted because negative in GM (e.g, "don't")
gen->set_show_cursor(dec.readBool());
gfx->set_window_scale(dec.read4());
gfx->set_view_scale(dec.read4());
if (ver == 530) {
dec.skip(8); // "fullscreen scale" & "only scale w/ hardware support"
} else {
gfx->set_window_sizeable(dec.readBool());
gfx->set_window_stayontop(dec.readBool());
gen->set_color_outside_room_region(dec.read4());
win->set_is_sizeable(dec.readBool());
win->set_stay_on_top(dec.readBool());
gfx->set_color_outside_room_region(dec.read4());
}
dec.readBool(); // set_resolution

@@ -486,7 +487,7 @@ int LoadSettings(Decoder &dec, Settings& set) {
dec.read4(); // frequency
}

gfx->set_window_showicons(!dec.readBool()); // inverted because negative in GM (e.g, "don't")
win->set_show_icons(!dec.readBool()); // inverted because negative in GM (e.g, "don't")
if (ver > 530) gfx->set_use_synchronization(dec.readBool());
if (ver >= 800) dec.readBool(); // DISABLE_SCREENSAVERS
gfx->set_allow_fullscreen_change(dec.readBool());
@@ -498,7 +499,7 @@ int LoadSettings(Decoder &dec, Settings& set) {
dec.readBool(); dec.readBool();
}
dec.read4(); // GAME_PRIORITY
gfx->set_freeze_on_lose_focus(dec.readBool());
win->set_freeze_on_lose_focus(dec.readBool());
int load_bar_mode = dec.read4(); // LOAD_BAR_MODE
if (load_bar_mode == 2) { // 0=NONE 1=DEFAULT 2=CUSTOM
if (ver < 800) {
@@ -810,11 +811,22 @@ std::unique_ptr<Font> LoadFont(Decoder &dec, int /*ver*/) {
return font;
}

int LoadActions(Decoder &dec, Event *event) {
// TODO: Look up event name by type integer
string Describe(const Event &ev) {
string res = "Event " + to_string(ev.type()) + ":";
if (ev.has_name()) return res + ev.name();
return res + to_string(ev.number());
}

string Describe(const Timeline_Moment &m) {
return "Timeline moment " + to_string(m.step());
}

template<class Event> int LoadActions(Decoder &dec, Event *event) {
int ver = dec.read4();
if (ver != 400) {
err << "Unsupported GMK actions version '" << ver << "' for event type '" << event->type()
<< "' and number '" << event->number() << "'" << std::endl;
err << "Unsupported GMK actions version '" << ver << "' for "
<< Describe(*event) << "'" << std::endl;
return 0;
}

@@ -897,7 +909,7 @@ std::unique_ptr<Timeline> LoadTimeline(Decoder &dec, int /*ver*/) {
for (int i = 0; i < nomoms; i++) {
auto moment = timeline->add_moments();
moment->set_step(dec.read4());
if (!LoadActions(dec, moment->mutable_event())) return nullptr;
if (!LoadActions(dec, moment)) return nullptr;
}

return timeline;
@@ -944,7 +956,7 @@ std::unique_ptr<Room> LoadRoom(Decoder &dec, int ver) {
room->set_persistent(dec.readBool());
room->set_color(dec.read4());
room->set_show_color(dec.readBool());
room->set_code(dec.readStr());
room->set_creation_code(dec.readStr());

int nobackgrounds = dec.read4();
for (int j = 0; j < nobackgrounds; j++) {
@@ -994,7 +1006,7 @@ std::unique_ptr<Room> LoadRoom(Decoder &dec, int ver) {
instance->set_y(dec.read4());
dec.postponeName(instance->mutable_object_type(), dec.read4(), TypeCase::kObject);
instance->set_id(dec.read4());
instance->set_code(dec.readStr());
instance->set_creation_code(dec.readStr());
instance->mutable_editor_settings()->set_locked(dec.readBool());
}

@@ -30,16 +30,18 @@ endif

CXX := g++
CXXFLAGS += -std=c++11 -Wall -O3 -g -I./JDI/src
LDFLAGS += -shared -O3 -g
LDFLAGS += -shared -O3 -g -L../ -Wl,-rpath=./
LDLIBS += -lProtocols -lprotobuf

# This implements a recursive wildcard allowing us to iterate in subdirs
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

SOURCES := $(filter-out ./standalone_main.cpp, $(call rwildcard,./,*.cpp))
OBJECTS := $(addprefix .eobjs/,$(SOURCES:.cpp=.o))
DEPENDS := $(OBJECTS:.o=.d)
PROTO_DIR := ../shared/protos

CXXFLAGS += -I../shared $(addprefix -I../shared/, $(SHARED_INCLUDES))
CXXFLAGS += -I../shared -I$(PROTO_DIR)/codegen $(addprefix -I../shared/, $(SHARED_INCLUDES))
SOURCES += $(addprefix $(SHARED_SRC_DIR),$(SHARED_SOURCES))
OBJECTS += $(addprefix .eobjs/shared/,$(SHARED_SOURCES:.cpp=.o))
DEPENDS += $(addprefix .eobjs/shared/,$(SHARED_SOURCES:.cpp=.d))
@@ -28,6 +28,8 @@
#include "other/Include.h"
#include "other/Extension.h"

/// Structure once used for communicating game information between an IDE via
/// a shared-memory model. @deprecated Use `GameData` instead.
struct EnigmaStruct
{
int fileVersion;
Oops, something went wrong.

0 comments on commit a1aa34d

Please sign in to comment.