@rm -f $(OUTDIR)/$*.$(DEPEXT).tmp
.PHONY: all remake clean cleaner resources
+
+game.loadFont("freepixel16", "Assets/FreePixel.ttf", 16)
+
bird = {
Player = 0,
EventListeners = {
#include "script.hpp"
#include "render.hpp"
#include "physics.hpp"
+#include "text.hpp"
#include "components/EventListener.hpp"
#include "components/Script.hpp"
systems.add<RenderSystem>();
systems.add<ScriptSystem>(entities);
systems.add<PhysicsSystem>();
+ systems.add<TextSystem>();
systems.configure();
// Load game script and entity data
- systems.system<ScriptSystem>()->init();
+ auto* script = systems.system<ScriptSystem>().get();
+ script->addToGameNamespace("loadFont",
+ [this](std::string name, std::string file, int size) {
+ systems.system<TextSystem>().get()->loadFont(name, file, size);
+ });
+ script->init();
+
+
if (GameState::load("save.json", entities)) {
std::cout << "Loaded from save.json. Delete the file if you don't want "
"it." << std::endl;
// Init after systems.configure() in engine.cpp
//init();
+ lua.open_libraries(sol::lib::base, sol::lib::math, sol::lib::string);
+
+ scriptExport();
}
#include <components/Script.hpp>
int ScriptSystem::init(void)
{
- lua.open_libraries(sol::lib::base, sol::lib::math, sol::lib::string);
-
- scriptExport();
doFile();
return 0;
void ScriptSystem::scriptExport(void)
{
- std::function<sol::table(sol::table)> func =
- [this](sol::table t){ return spawn(t);};
-
lua.new_usertype<Position>("Position",
sol::constructors<Position(double x, double y), Position()>(),
"x", &Position::x,
sol::constructors<Physics(void), Physics()>(),
"standing", &Physics::standing);
- auto gamespace = lua["game"].get_or_create<sol::table>();
- gamespace.set_function("spawn", func);
+ game = lua["game"].get_or_create<sol::table>();
+ game.set_function("spawn", [this](sol::table t) { return spawn(t); });
}
sol::table ScriptSystem::spawn(sol::object param)
* interactions between C and Lua
*/
sol::state lua;
+ sol::table game;
entityx::EntityManager& manager;
* Contains all calls that export components/functions to lua.
*/
void scriptExport(void);
+
+ template<typename F>
+ void addToGameNamespace(const std::string& name, F func) {
+ game.set_function(name, func);
+ }
};
#endif // SYSTEM_SCRIPT_HPP_
#include "text.hpp"
-#include <SDL2/SDL_opengl.h>
-
-#include <tuple>
-
-struct FT_Info {
- std::pair<float, float> wh;
- std::pair<float, float> bl;
- std::pair<float, float> ad;
- GLuint tex;
-
- FT_Info(void)
- : tex(0) {}
-};
+#include <iostream>
//FT_Library freetype;
//std::map<std::string, FT_Face> fonts;
int size)
{
- if (fonts.find(name) == fonts.end()) {
+ if (fonts.find(file) == fonts.end()) {
FT_Face face;
if (FT_New_Face(freetype, file.c_str(), 0, &face)) {
// TODO handle this error
}
- fonts.emplace(name, face);
+ fonts.emplace(file, face);
}
- auto& face = fonts[name];
+ auto& face = fonts[file];
FT_Set_Pixel_Sizes(face, 0, size);
fontData.try_emplace(name, 95);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g->bitmap.width, g->bitmap.rows,
0, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
}
+
+ std::cout << "Loaded font: " << file << " (size: " << size << ')'
+ << std::endl;
}
#include <entityx/entityx.h>
#include <ft2build.h>
#include <freetype/freetype.h>
+#include <SDL2/SDL_opengl.h>
+
#include <map>
#include <string>
+#include <tuple>
#include <vector>
-struct FT_Info;
+struct FT_Info {
+ std::pair<float, float> wh;
+ std::pair<float, float> bl;
+ std::pair<float, float> ad;
+ GLuint tex;
+
+ FT_Info(void)
+ : tex(0) {}
+};
/**
* @class PhysicsSystem