Skip to content
Permalink
Browse files

Isolate EnigmaStruct family of structures. (#1595)

* Isolate EnigmaStruct family of structures. Move them to namespace `deprecated::JavaStruct` where they won't interfere with protos and other libraries.
* Delete Instance.c: it doesn't appear to have ever been used.
* Update references to EnigmaStruct in emake.
  • Loading branch information...
JoshDreamland committed Mar 16, 2019
2 parents 996bcfb + d37731c commit 6d3486cf17aebdaf091cd0831a74409326260b57
Showing with 241 additions and 79 deletions.
  1. +3 −3 CommandLine/emake/EnigmaPlugin.cpp
  2. +2 −2 CommandLine/emake/EnigmaPlugin.hpp
  3. +1 −0 CommandLine/emake/Game.cpp
  4. +16 −16 CommandLine/emake/Game.hpp
  5. +5 −3 CompilerSource/backend/EnigmaStruct.h
  6. +16 −15 CompilerSource/backend/GameData.cpp
  7. +13 −13 CompilerSource/backend/GameData.h
  8. +2 −2 CompilerSource/backend/JavaCallbacks.cpp
  9. +14 −10 CompilerSource/backend/JavaStruct.h
  10. +6 −0 CompilerSource/backend/other/Constant.h
  11. +6 −0 CompilerSource/backend/other/Extension.h
  12. +6 −0 CompilerSource/backend/other/Include.h
  13. +6 −0 CompilerSource/backend/other/Trigger.h
  14. +6 −0 CompilerSource/backend/resources/Background.h
  15. +6 −0 CompilerSource/backend/resources/Font.h
  16. +6 −0 CompilerSource/backend/resources/GameInformation.h
  17. +6 −0 CompilerSource/backend/resources/GameSettings.h
  18. +6 −0 CompilerSource/backend/resources/GmObject.h
  19. +6 −0 CompilerSource/backend/resources/Path.h
  20. +6 −0 CompilerSource/backend/resources/Room.h
  21. +6 −0 CompilerSource/backend/resources/Script.h
  22. +6 −0 CompilerSource/backend/resources/Shader.h
  23. +6 −0 CompilerSource/backend/resources/Sound.h
  24. +6 −0 CompilerSource/backend/resources/Sprite.h
  25. +6 −0 CompilerSource/backend/resources/Timeline.h
  26. +6 −0 CompilerSource/backend/sub/Action.h
  27. +6 −0 CompilerSource/backend/sub/BackgroundDef.h
  28. +6 −0 CompilerSource/backend/sub/Event.h
  29. +6 −0 CompilerSource/backend/sub/Glyph.h
  30. +6 −0 CompilerSource/backend/sub/GlyphRange.h
  31. +0 −14 CompilerSource/backend/sub/Instance.c
  32. +6 −0 CompilerSource/backend/sub/Instance.h
  33. +6 −0 CompilerSource/backend/sub/MainEvent.h
  34. +6 −0 CompilerSource/backend/sub/Moment.h
  35. +6 −0 CompilerSource/backend/sub/PathPoint.h
  36. +6 −0 CompilerSource/backend/sub/SubImage.h
  37. +6 −0 CompilerSource/backend/sub/Tile.h
  38. +6 −0 CompilerSource/backend/sub/View.h
  39. +1 −1 CompilerSource/compiler/compile.cpp
@@ -63,7 +63,7 @@ int EnigmaPlugin::Load()
#endif

plugin_Init = reinterpret_cast<const char*(*)(EnigmaCallbacks*)>(BindFunc(_handle, "libInit"));
plugin_CompileEGM = reinterpret_cast<int (*)(EnigmaStruct *es, const char* exe_filename, int mode)>(BindFunc(_handle, "compileEGMf"));
plugin_CompileEGM = reinterpret_cast<int (*)(deprecated::JavaStruct::EnigmaStruct *es, const char* exe_filename, int mode)>(BindFunc(_handle, "compileEGMf"));
plugin_CompileProto = reinterpret_cast<int (*)(const buffers::Project *proj, const char* exe_filename, int mode)>(BindFunc(_handle, "compileProto"));
plugin_NextResource = reinterpret_cast<const char* (*)()>(BindFunc(_handle, "next_available_resource"));
plugin_FirstResource = reinterpret_cast<const char* (*)()>(BindFunc(_handle, "first_available_resource"));
@@ -114,8 +114,8 @@ void EnigmaPlugin::LogMakeToConsole()
plugin_LogMakeToConsole();
}

int EnigmaPlugin::BuildGame(EnigmaStruct* data, GameMode mode, const char* fpath)
{
int EnigmaPlugin::BuildGame(deprecated::JavaStruct::EnigmaStruct* data,
GameMode mode, const char* fpath) {
return plugin_CompileEGM(data, fpath, mode);
}

@@ -37,7 +37,7 @@ class EnigmaPlugin
syntax_error* SyntaxCheck(int count, const char** names, const char* code);
void HandleGameLaunch();
void LogMakeToConsole();
int BuildGame(EnigmaStruct* data, GameMode mode, const char* fpath);
int BuildGame(deprecated::JavaStruct::EnigmaStruct* data, GameMode mode, const char* fpath);
int BuildGame(buffers::Game* data, GameMode mode, const char* fpath);
const char* NextResource();
const char* FirstResource();
@@ -53,7 +53,7 @@ class EnigmaPlugin

private:
std::function<const char*(EnigmaCallbacks*)> plugin_Init = nullptr;
std::function<int(EnigmaStruct*, const char*, int)> plugin_CompileEGM = nullptr;
std::function<int(deprecated::JavaStruct::EnigmaStruct*, const char*, int)> plugin_CompileEGM = nullptr;
std::function<int(const buffers::Project *proj, const char*, int)> plugin_CompileProto = nullptr;
std::function<const char*()> plugin_NextResource = nullptr;
std::function<const char*()> plugin_FirstResource = nullptr;
@@ -6,6 +6,7 @@ using std::string;

namespace {

using namespace deprecated::JavaStruct;
constexpr int NO_SPRITE = -1;
constexpr int NO_OBJECT = -1;
constexpr int INSTANCE_ID_MIN = 100001;
@@ -12,30 +12,30 @@ class Game
public:
void AddSimpleObject(const std::map<std::pair<int,int>, std::string> &events);
void AddDefaultRoom();
EnigmaStruct* ConstructGame();
deprecated::JavaStruct::EnigmaStruct* ConstructGame();
void SetOutputFile(std::string fName);

protected:
EnigmaStruct _game;
deprecated::JavaStruct::EnigmaStruct _game;
std::string _output_filename;
std::vector<Script> _scripts;
std::vector<Sprite> _sprites;
std::vector<Shader> _shaders;
std::vector<Sound> _sounds;
std::vector<Font> _fonts;
std::vector<Background> _backgrounds;
std::vector<Path> _paths;
std::vector<Timeline> _timelines;
std::vector<GmObject> _objects;
std::vector<Room> _rooms;
std::vector<deprecated::JavaStruct::Script> _scripts;
std::vector<deprecated::JavaStruct::Sprite> _sprites;
std::vector<deprecated::JavaStruct::Shader> _shaders;
std::vector<deprecated::JavaStruct::Sound> _sounds;
std::vector<deprecated::JavaStruct::Font> _fonts;
std::vector<deprecated::JavaStruct::Background> _backgrounds;
std::vector<deprecated::JavaStruct::Path> _paths;
std::vector<deprecated::JavaStruct::Timeline> _timelines;
std::vector<deprecated::JavaStruct::GmObject> _objects;
std::vector<deprecated::JavaStruct::Room> _rooms;

std::vector<std::vector<MainEvent>> _main_events;
std::vector<std::vector<Event>> _events;
std::vector<std::vector<Instance>> _instances;
std::vector<std::vector<deprecated::JavaStruct::MainEvent>> _main_events;
std::vector<std::vector<deprecated::JavaStruct::Event>> _events;
std::vector<std::vector<deprecated::JavaStruct::Instance>> _instances;
std::vector<std::string> _strings;

const char* SS(std::string str);
void AddSimpleEvent(std::vector<MainEvent>* main_events,
void AddSimpleEvent(std::vector<deprecated::JavaStruct::MainEvent>* main_events,
int main_id, int id, std::string code);
};

@@ -28,6 +28,9 @@
#include "other/Include.h"
#include "other/Extension.h"

namespace deprecated {
namespace JavaStruct {

/// Structure once used for communicating game information between an IDE via
/// a shared-memory model. @deprecated Use `GameData` instead.
struct EnigmaStruct
@@ -76,8 +79,7 @@ struct EnigmaStruct
int lastTileId;
};

#undef String
#undef boolean
#undef byte
} // namespace JavaStruct
} // namespace deprecated

#endif
@@ -107,7 +107,7 @@ struct ESLookup {
}
};
Lookup sprite, background, script, object;
ESLookup(EnigmaStruct *es):
ESLookup(deprecated::JavaStruct::EnigmaStruct *es):
sprite(es->sprites, es->spriteCount, "sprite"),
background(es->backgrounds, es->backgroundCount, "background"),
script(es->scripts, es->scriptCount, "script"),
@@ -116,7 +116,7 @@ struct ESLookup {

SpriteData::SpriteData(const buffers::resources::Sprite &q, const std::string& name, const std::vector<ImageData>& subimages):
BaseProtoWrapper(q), name(name), image_data(subimages) {}
SpriteData::SpriteData(const ::Sprite &sprite):
SpriteData::SpriteData(const deprecated::JavaStruct::Sprite &sprite):
name(sprite.name) {
data.set_id(sprite.id);

@@ -143,7 +143,7 @@ SpriteData::SpriteData(const ::Sprite &sprite):

SoundData::SoundData(const buffers::resources::Sound &q, const std::string& name, const BinaryData& data):
BaseProtoWrapper(q), name(name), audio(data) {}
SoundData::SoundData(const ::Sound &sound):
SoundData::SoundData(const deprecated::JavaStruct::Sound &sound):
name(sound.name),
audio(sound.data, sound.data + sound.size) {
data.set_id(sound.id);
@@ -164,7 +164,7 @@ SoundData::SoundData(const ::Sound &sound):

BackgroundData::BackgroundData(const buffers::resources::Background &q, const std::string& name, const ImageData& image):
BaseProtoWrapper(q), name(name), image_data(image) {}
BackgroundData::BackgroundData(const ::Background &background):
BackgroundData::BackgroundData(const deprecated::JavaStruct::Background &background):
name(background.name),
image_data(background.backgroundImage) {
data.set_id(background.id);
@@ -185,7 +185,7 @@ BackgroundData::BackgroundData(const ::Background &background):

FontData::FontData(const buffers::resources::Font &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
FontData::FontData(const ::Font &font):
FontData::FontData(const deprecated::JavaStruct::Font &font):
name(font.name) {
data.set_id(font.id);

@@ -202,7 +202,7 @@ FontData::FontData(const ::Font &font):
}
}

FontData::NormalizedRange::NormalizedRange(const ::GlyphRange &range):
FontData::NormalizedRange::NormalizedRange(const deprecated::JavaStruct::GlyphRange &range):
min(range.rangeMin), max(range.rangeMax) {
const int gcount = range.rangeMax - range.rangeMin + 1;
glyphs.reserve(gcount);
@@ -211,7 +211,7 @@ FontData::NormalizedRange::NormalizedRange(const ::GlyphRange &range):
}
}

FontData::GlyphData::GlyphData(const ::Glyph &glyph):
FontData::GlyphData::GlyphData(const deprecated::JavaStruct::Glyph &glyph):
ImageData(glyph.width, glyph.height, glyph.data,
glyph.width * glyph.height) { // Glyph images are alpha-only.
metrics.set_origin(glyph.origin);
@@ -223,7 +223,7 @@ FontData::GlyphData::GlyphData(const ::Glyph &glyph):

PathData::PathData(const buffers::resources::Path &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
PathData::PathData(const ::Path &path):
PathData::PathData(const deprecated::JavaStruct::Path &path):
name(path.name) {
data.set_id(path.id);

@@ -245,15 +245,15 @@ PathData::PathData(const ::Path &path):

ScriptData::ScriptData(const buffers::resources::Script &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
ScriptData::ScriptData(const ::Script &script):
ScriptData::ScriptData(const deprecated::JavaStruct::Script &script):
name(script.name) {
data.set_id(script.id);
data.set_code(script.code);
}

ShaderData::ShaderData(const buffers::resources::Shader &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
ShaderData::ShaderData(const ::Shader &shader):
ShaderData::ShaderData(const deprecated::JavaStruct::Shader &shader):
name(shader.name) {
data.set_id(shader.id);

@@ -266,7 +266,7 @@ ShaderData::ShaderData(const ::Shader &shader):

TimelineData::TimelineData(const buffers::resources::Timeline &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
TimelineData::TimelineData(const ::Timeline &timeline):
TimelineData::TimelineData(const deprecated::JavaStruct::Timeline &timeline):
name(timeline.name) {
data.set_id(timeline.id);

@@ -279,7 +279,7 @@ TimelineData::TimelineData(const ::Timeline &timeline):

ObjectData::ObjectData(const buffers::resources::Object &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
ObjectData::ObjectData(const ::GmObject &object, const ESLookup &lookup):
ObjectData::ObjectData(const deprecated::JavaStruct::GmObject &object, const ESLookup &lookup):
name(object.name) {
data.set_id(object.id);

@@ -306,7 +306,7 @@ ObjectData::ObjectData(const ::GmObject &object, const ESLookup &lookup):

RoomData::RoomData(const buffers::resources::Room &q, const std::string& name):
BaseProtoWrapper(q), name(name) {}
RoomData::RoomData(const ::Room &room, const ESLookup &lookup):
RoomData::RoomData(const deprecated::JavaStruct::Room &room, const ESLookup &lookup):
name(room.name) {
cout << "Import room." << endl;
data.set_id(room.id);
@@ -399,7 +399,8 @@ RoomData::RoomData(const ::Room &room, const ESLookup &lookup):
}
}

static void ImportSettings(const ::GameSettings &settings, const ESLookup &lookup, buffers::resources::Settings& set) {
static void ImportSettings(const deprecated::JavaStruct::GameSettings &settings,
const ESLookup &lookup, buffers::resources::Settings& set) {
cout << "Import game settings." << endl;

buffers::resources::General *gen = set.mutable_general();
@@ -458,7 +459,7 @@ ImageData::ImageData(const Image &img):
ImageData::ImageData(int w, int h, const uint8_t *data, size_t size):
width(w), height(h), pixels(data, data + size) {}

GameData::GameData(EnigmaStruct *es): filename(es->filename ?: "") {
GameData::GameData(deprecated::JavaStruct::EnigmaStruct *es): filename(es->filename ?: "") {
cout << "Translating EnigmaStruct" << endl;
cout << "- Indexing names" << endl;
ESLookup lookup(es);
@@ -56,7 +56,7 @@ struct SpriteData : ProtoMessageInheritor<buffers::resources::Sprite> {

SpriteData(const BaseProtoClass &sprite,
const std::string& name, const std::vector<ImageData>& subimages);
SpriteData(const ::Sprite &sprite);
SpriteData(const deprecated::JavaStruct::Sprite &sprite);
};

struct SoundData : ProtoMessageInheritor<buffers::resources::Sound> {
@@ -65,7 +65,7 @@ struct SoundData : ProtoMessageInheritor<buffers::resources::Sound> {

SoundData(const BaseProtoClass &sound,
const std::string& name, const BinaryData& data);
SoundData(const ::Sound &sound);
SoundData(const deprecated::JavaStruct::Sound &sound);
};

struct BackgroundData : ProtoMessageInheritor<buffers::resources::Background> {
@@ -75,7 +75,7 @@ struct BackgroundData : ProtoMessageInheritor<buffers::resources::Background> {

BackgroundData(const BaseProtoClass &background,
const std::string& name, const ImageData& image);
BackgroundData(const ::Background &background);
BackgroundData(const deprecated::JavaStruct::Background &background);
};

struct FontData : ProtoMessageInheritor<buffers::resources::Font> {
@@ -85,51 +85,51 @@ struct FontData : ProtoMessageInheritor<buffers::resources::Font> {

// TODO: Need to move the font packing logic to allow pre-packed sprite
// fonts; cannot construct image here in the meantime
GlyphData(const ::Glyph &glyph);
GlyphData(const deprecated::JavaStruct::Glyph &glyph);
};
struct NormalizedRange {
int min, max;
std::vector<GlyphData> glyphs;
NormalizedRange(int min_, int max_): min(min_), max(max_) {
glyphs.reserve(max_ - min_ + 1);
}
NormalizedRange(const ::GlyphRange &range);
NormalizedRange(const deprecated::JavaStruct::GlyphRange &range);
};
std::vector<NormalizedRange> normalized_ranges;

FontData(const BaseProtoClass &font, const std::string& name);
FontData(const ::Font &font);
FontData(const deprecated::JavaStruct::Font &font);
};

struct PathData : ProtoMessageInheritor<buffers::resources::Path> {
std::string name;
PathData(const BaseProtoClass &q, const std::string& name);
PathData(const ::Path &path);
PathData(const deprecated::JavaStruct::Path &path);
};
struct ScriptData : ProtoMessageInheritor<buffers::resources::Script> {
std::string name;
ScriptData(const BaseProtoClass &q, const std::string& name);
ScriptData(const ::Script &script);
ScriptData(const deprecated::JavaStruct::Script &script);
};
struct ShaderData : ProtoMessageInheritor<buffers::resources::Shader> {
std::string name;
ShaderData(const BaseProtoClass &q, const std::string& name);
ShaderData(const ::Shader &shader);
ShaderData(const deprecated::JavaStruct::Shader &shader);
};
struct TimelineData : ProtoMessageInheritor<buffers::resources::Timeline> {
std::string name;
TimelineData(const BaseProtoClass &q, const std::string& name);
TimelineData(const ::Timeline &timeline);
TimelineData(const deprecated::JavaStruct::Timeline &timeline);
};
struct ObjectData : ProtoMessageInheritor<buffers::resources::Object> {
std::string name;
ObjectData(const BaseProtoClass &q, const std::string& name);
ObjectData(const ::GmObject &object, const ESLookup &lookup);
ObjectData(const deprecated::JavaStruct::GmObject &object, const ESLookup &lookup);
};
struct RoomData : ProtoMessageInheritor<buffers::resources::Room> {
std::string name;
RoomData(const BaseProtoClass &q, const std::string& name);
RoomData(const ::Room &room, const ESLookup &lookup);
RoomData(const deprecated::JavaStruct::Room &room, const ESLookup &lookup);
};

/// Flat view of a buffers::Project.
@@ -167,7 +167,7 @@ struct GameData {
buffers::resources::GameInformation gameInfo;
buffers::resources::Settings settings;

GameData(struct EnigmaStruct *es);
GameData(struct deprecated::JavaStruct::EnigmaStruct *es);
GameData(const buffers::Project &proj);
};

@@ -23,7 +23,7 @@
static void javano_signal() { puts(ER_NoIdeFunc); }
static void javano_signal_i(int) { puts(ER_NoIdeFunc); }
static void javano_signal_cstr(const char*) { puts(ER_NoIdeFunc); }
static int javano_signal_exec(String, String *, boolean) { puts(ER_NoIdeFunc); return -1; }
static int javano_signal_exec(const char*, const char**, int) { puts(ER_NoIdeFunc); return -1; }
static Image *javano_signal_buffer(char *, int) { puts(ER_NoIdeFunc); return NULL; }

//Opens the EnigmaFrame
@@ -43,6 +43,6 @@ void (*ide_output_redirect_file) (const char *) = javano_signal_cstr;
void (*ide_output_redirect_reset) () = javano_signal;

//Executes a given command, returns errors or ret val
int (*ide_execute) (String, String *, boolean) = javano_signal_exec;
int (*ide_execute) (const char*, const char**, int) = javano_signal_exec;
//Compresses data. Note image width/height unused.
Image* (*ide_compress_data) (char *, int) = javano_signal_buffer;
@@ -5,14 +5,18 @@
* Enigma Plugin is free software and comes with ABSOLUTELY NO WARRANTY.
* See LICENSE for details.
*/

#ifndef JAVASTRUCT_H
#define JAVASTRUCT_H

namespace deprecated {
namespace JavaStruct {

#ifdef JAVASTRUCT_H
# undef String
# undef boolean
# undef byte
#else
# define JAVASTRUCT_H
#endif
#define String const char*
#define boolean int
#define byte unsigned char
using String = const char*;
using boolean = int;
using byte = unsigned char;

} // namespace JavaStruct
} // namespace deprecated

#endif // JAVASTRUCT_H
Oops, something went wrong.

0 comments on commit 6d3486c

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.