Skip to content

Commit 2e457e4

Browse files
committed
Merge pull request #1 from rpgtoolkit/develop
Develop to Master
2 parents 822b4be + 62dc1e5 commit 2e457e4

File tree

17 files changed

+570
-218
lines changed

17 files changed

+570
-218
lines changed

cmake/projects/trans4.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ set(RPGTOOLKIT_TRANS4_HEADERS
3434
${RPGTOOLKIT_HEADERS}/trans4/assets/serializers/LegacyTilesetSerializer.hpp
3535
${RPGTOOLKIT_HEADERS}/trans4/io/BinaryReader.hpp
3636
${RPGTOOLKIT_HEADERS}/trans4/game/Game.hpp
37+
${RPGTOOLKIT_HEADERS}/trans4/scripts/Canvas.hpp
38+
${RPGTOOLKIT_HEADERS}/trans4/scripts/LuaCommand.hpp
3739
${RPGTOOLKIT_HEADERS}/trans4/scripts/LuaGameState.hpp
3840
${RPGTOOLKIT_HEADERS}/trans4/scripts/LuaScriptEngine.hpp
3941
${RPGTOOLKIT_HEADERS}/trans4/scripts/ScriptEngine.hpp
@@ -42,6 +44,8 @@ set(RPGTOOLKIT_TRANS4_HEADERS
4244

4345
set(RPGTOOLKIT_TRANS4_SOURCES
4446
${RPGTOOLKIT_SOURCES}/trans4/trans4.cpp
47+
${RPGTOOLKIT_SOURCES}/trans4/Engine.cpp
48+
${RPGTOOLKIT_SOURCES}/trans4/Version.cpp
4549
${RPGTOOLKIT_SOURCES}/trans4/assets/AssetHandle.cpp
4650
${RPGTOOLKIT_SOURCES}/trans4/assets/AssetRepository.cpp
4751
${RPGTOOLKIT_SOURCES}/trans4/assets/GameManifest.cpp
@@ -54,6 +58,8 @@ set(RPGTOOLKIT_TRANS4_SOURCES
5458
${RPGTOOLKIT_SOURCES}/trans4/assets/serializers/LegacyTilesetSerializer.cpp
5559
${RPGTOOLKIT_SOURCES}/trans4/game/Game.cpp
5660
${RPGTOOLKIT_SOURCES}/trans4/io/BinaryReader.cpp
61+
${RPGTOOLKIT_SOURCES}/trans4/scripts/Canvas.cpp
62+
${RPGTOOLKIT_SOURCES}/trans4/scripts/LuaCommand.cpp
5763
${RPGTOOLKIT_SOURCES}/trans4/scripts/LuaGameState.cpp
5864
${RPGTOOLKIT_SOURCES}/trans4/scripts/LuaScriptEngine.cpp
5965
${RPGTOOLKIT_SOURCES}/trans4/scripts/ScriptEngine.cpp

include/trans4/Engine.hpp

Lines changed: 16 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/// \copyright
2+
///
3+
/// See LICENSE.md in the distribution for the full license text including,
4+
/// but not limited to, a notice of warranty and distribution rights.
5+
16
#ifndef RPGTOOLKIT_TRANS4_ENGINE_INCLUDED
27
#define RPGTOOLKIT_TRANS4_ENGINE_INCLUDED
38

@@ -7,6 +12,8 @@
712
#include "clio/system/SystemSettings.hpp"
813
#include "clio/window/Window.hpp"
914
#include "clio/common/Logger.hpp"
15+
#include "clio/graphics/Texture.hpp"
16+
#include "clio/graphics/Renderer2D.hpp"
1017

1118
#include "Version.hpp"
1219
#include "game/Game.hpp"
@@ -24,110 +31,28 @@ namespace rpgtoolkit {
2431

2532
struct Engine {
2633

27-
const char * DEFAULT_LOG_FILENAME = "trans4.log";
28-
const char * DEFAULT_SCRIPT_FILENAME = "main.lua";
29-
30-
static Engine & GetInstance() {
31-
32-
static Engine instance;
33-
return instance;
34-
35-
}
34+
static Engine & GetInstance();
3635

3736
void
38-
Configure() {
39-
40-
clio::SystemSettings settings;
41-
42-
// Configure default system settings
43-
44-
settings.window.x = settings.window.POSITION_CENTERED;
45-
settings.window.y = settings.window.POSITION_CENTERED;
46-
settings.window.width = 640;
47-
settings.window.height = 480;
48-
settings.window.init_flags = 0;
49-
50-
// Look for a game manifest in the current working directory
51-
// and load settings from this file.
52-
53-
auto manifest = assets_.Load<GameManifest>("file://main.gam");
54-
55-
if (manifest) {
56-
57-
settings.window.width = manifest->GetResolutionWidth();
58-
settings.window.height = manifest->GetResolutionHeight();
59-
60-
switch (manifest->GetDisplayMode()) {
61-
case DisplayMode::FULLSCREEN:
62-
settings.window.init_flags |= settings.window.FULLSCREEN;
63-
break;
64-
case DisplayMode::BORDERLESS:
65-
settings.window.init_flags |= settings.window.BORDERLESS;
66-
break;
67-
default:
68-
break;
69-
}
70-
71-
}
72-
73-
system_->Initialize(settings);
74-
75-
system_->GetWindow()->SetTitle(
76-
manifest ? manifest->GetTitle() : "RPG Toolkit 4.0");
77-
78-
}
37+
Configure();
7938

8039
void
81-
Run() {
82-
83-
LOG(&log_, "RPG Toolkit %s", GetVersion().ToString().c_str());
84-
85-
scripting_.Run(DEFAULT_SCRIPT_FILENAME);
86-
game_.Run();
87-
88-
}
40+
Run();
8941

9042
ScriptEngine &
91-
GetScriptEngine() {
92-
93-
return scripting_;
94-
95-
}
43+
GetScriptEngine();
9644

9745
AssetRepository &
98-
GetAssets() {
99-
100-
return assets_;
101-
102-
}
46+
GetAssets();
10347

10448
clio::Logger
105-
GetLog() {
106-
107-
return log_;
108-
109-
}
49+
GetLog();
11050

11151
Game &
112-
GetGame() {
113-
114-
return game_;
115-
116-
}
52+
GetGame();
11753

11854
Version const &
119-
GetVersion() const {
120-
121-
static Version v(
122-
RPGTOOLKIT_VERSION_MAJOR,
123-
RPGTOOLKIT_VERSION_MINOR,
124-
RPGTOOLKIT_VERSION_PATCH,
125-
RPGTOOLKIT_VERSION_RELEASE,
126-
RPGTOOLKIT_VERSION_METADATA);
127-
128-
return v;
129-
130-
}
55+
GetVersion() const;
13156

13257
private:
13358

@@ -143,22 +68,7 @@ namespace rpgtoolkit {
14368

14469
Engine(Engine const & rhs) = delete;
14570

146-
Engine()
147-
: system_(new clio::System()),
148-
log_(DEFAULT_LOG_FILENAME),
149-
game_(system_.get()) {
150-
151-
// Initialize the scripting runtime
152-
153-
scripting_.Initialize(&game_, system_.get());
154-
155-
// Initialize supported repository resolvers and serializers
156-
157-
assets_.RegisterSerializer<LegacyGameManifestSerializer>();
158-
assets_.RegisterSerializer<LegacyTilesetSerializer>();
159-
assets_.RegisterResolver<FileAssetHandleResolver>();
160-
161-
}
71+
Engine();
16272

16373
};
16474

include/trans4/Version.hpp

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
/// \copyright
2+
///
3+
/// See LICENSE.md in the distribution for the full license text including,
4+
/// but not limited to, a notice of warranty and distribution rights.
5+
16
#ifndef RPGTOOLKIT_TRANS4_VERSION_INCLUDED
27
#define RPGTOOLKIT_TRANS4_VERSION_INCLUDED
38

49
#include <string>
510
#include <ostream>
6-
#include <sstream>
711

812
namespace rpgtoolkit {
913

10-
const int RPGTOOLKIT_VERSION_MAJOR = 4;
14+
static const int RPGTOOLKIT_VERSION_MAJOR = 4;
1115

12-
const int RPGTOOLKIT_VERSION_MINOR = 0;
16+
static const int RPGTOOLKIT_VERSION_MINOR = 0;
1317

14-
const int RPGTOOLKIT_VERSION_PATCH = 0;
18+
static const int RPGTOOLKIT_VERSION_PATCH = 0;
1519

16-
const char * RPGTOOLKIT_VERSION_RELEASE = "alpha";
20+
static const char RPGTOOLKIT_VERSION_RELEASE[] = "alpha";
1721

18-
const char * RPGTOOLKIT_VERSION_METADATA = "";
22+
static const char RPGTOOLKIT_VERSION_METADATA[] = "";
1923

2024
using std::string;
2125
using std::stringstream;
@@ -25,55 +29,27 @@ namespace rpgtoolkit {
2529
struct Version {
2630

2731
Version(short major, short minor, short patch,
28-
string const & release, string const & metadata)
29-
: major_(major), minor_(minor), patch_(patch),
30-
release_(release), metadata_(metadata) {
31-
}
32+
string const & release, string const & metadata);
3233

33-
Version(short major, short minor, short patch)
34-
: major_(major), minor_(minor), patch_(patch) {
35-
}
34+
Version(short major, short minor, short patch);
3635

3736
short
38-
GetMajor() const {
39-
return major_;
40-
}
37+
GetMajor() const;
4138

4239
short
43-
GetMinor() const {
44-
return minor_;
45-
}
40+
GetMinor() const;
4641

4742
short
48-
GetPatch() const {
49-
return patch_;
50-
}
43+
GetPatch() const;
5144

5245
string const &
53-
GetRelease() const {
54-
return release_;
55-
}
46+
GetRelease() const;
5647

5748
string const &
58-
GetBuildMetadata() const {
59-
return metadata_;
60-
}
49+
GetBuildMetadata() const;
6150

6251
string const
63-
ToString() const {
64-
stringstream buffer;
65-
buffer << major_ << ".";
66-
buffer << minor_ << ".";
67-
buffer << patch_;
68-
if (!release_.empty()) {
69-
buffer << "-" << release_;
70-
}
71-
if (!metadata_.empty()) {
72-
buffer << "+" << metadata_;
73-
}
74-
return buffer.str();
75-
}
76-
52+
ToString() const;
7753

7854
private:
7955

include/trans4/assets/Tileset.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace rpgtoolkit {
2424

2525
struct Tileset : public Asset {
2626

27-
2827
Tileset (size_t dimension, size_t count);
2928

3029
size_t
@@ -33,15 +32,15 @@ namespace rpgtoolkit {
3332
size_t
3433
GetTileDimensions() const;
3534

36-
uint32_t *
35+
char *
3736
GetImageBuffer();
3837

3938
private:
4039

4140
size_t dimension_;
4241
size_t count_;
4342

44-
unique_ptr<uint32_t[]> buffer_;
43+
unique_ptr<char[]> buffer_;
4544

4645
};
4746

include/trans4/scripts/Canvas.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/// \copyright
2+
///
3+
/// See LICENSE.md in the distribution for the full license text including,
4+
/// but not limited to, a notice of warranty and distribution rights.
5+
6+
#ifndef RPGTOOLKIT_TRANS4_SCRIPTS_CANVAS_INCLUDED
7+
#define RPGTOOLKIT_TRANS4_SCRIPTS_CANVAS_INCLUDED
8+
9+
#include <cstdint>
10+
#include <memory>
11+
12+
namespace clio {
13+
struct Texture;
14+
struct TextureClip;
15+
struct Renderer2D;
16+
}
17+
18+
namespace rpgtoolkit {
19+
struct Canvas {
20+
public:
21+
Canvas(clio::Renderer2D* renderer, size_t width, size_t height);
22+
23+
~Canvas();
24+
25+
void Render(int x, int y);
26+
27+
void DrawTexture(clio::Texture *texture, int x, int y, int w = 0, int h = 0);
28+
29+
void DrawTextureClip(clio::Texture* tex, int x, int y, int source_x, int source_y, int width, int height);
30+
31+
void DrawPixel(int x, int y);
32+
33+
void DrawLine(int x1, int y1, int x2, int y2);
34+
35+
void DrawRect(int x, int y, int width, int height);
36+
37+
void FillRect(int x, int y, int width, int height);
38+
39+
Canvas(Canvas const&);
40+
41+
Canvas & operator=(Canvas &);
42+
private:
43+
clio::Renderer2D* renderer_;
44+
45+
std::unique_ptr<clio::Texture> texture_;
46+
};
47+
}
48+
49+
#endif

include/trans4/scripts/LuaCommand.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef RPGTOOLKIT_TRANS4_SCRIPTS_LUACOMMAND_INCLUDED
2+
#define RPGTOOLKIT_TRANS4_SCRIPTS_LUACOMMAND_INCLUDED
3+
4+
#include "lua.hpp"
5+
#include "LuaBridge.h"
6+
7+
namespace rpgtoolkit {
8+
struct LuaCommand {
9+
public:
10+
LuaCommand(lua_State* L, const std::string& table, const std::string& function);
11+
12+
~LuaCommand();
13+
14+
/// \brief Execute the lua function
15+
void Execute();
16+
private:
17+
std::string function_;
18+
19+
luabridge::LuaRef luaTable_;
20+
};
21+
}
22+
23+
#endif

0 commit comments

Comments
 (0)