a5b68cf1fd
I've added lua hooks for both pager functor classes. Hopefully, I haven't missed any corner cases, because it took me a while to hunt everything down. One issue is that the map's save directory needs to be set in the Format class, but it'll do for now. I'll review this again when I've got more than one map running at one time. There should be enough here for a lua-driven map generator to be implemented, even if it's a bit rough. I think I'll test this out in the editor eventually, but getting the base branch's network map code going comes first. The current process is extremely convulted, so I need to document everything that I've done so far, including C++ and lua functions.
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
/* Copyright: (c) Kayne Ruse 2014
|
|
*
|
|
* This software is provided 'as-is', without any express or implied
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
* arising from the use of this software.
|
|
*
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
* including commercial applications, and to alter it and redistribute it
|
|
* freely, subject to the following restrictions:
|
|
*
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
* claim that you wrote the original software. If you use this software
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
* appreciated but is not required.
|
|
*
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
* misrepresented as being the original software.
|
|
*
|
|
* 3. This notice may not be removed or altered from any source
|
|
* distribution.
|
|
*/
|
|
#include "map_generator.hpp"
|
|
|
|
#include <stdexcept>
|
|
|
|
void BlankGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
|
(*ptr) = new Region(width, height, depth, x, y);
|
|
}
|
|
|
|
void BlankGenerator::Unload(Region* const ptr) {
|
|
delete ptr;
|
|
}
|
|
/*
|
|
void PerlinGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
|
(*ptr) = new Region(width, height, depth, x, y);
|
|
}
|
|
|
|
void PerlinGenerator::Unload(Region* const ptr) {
|
|
delete ptr;
|
|
}
|
|
*/
|
|
void LuaGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
|
//something to work on
|
|
(*ptr) = new Region(width, height, depth, x, y);
|
|
|
|
//API hook
|
|
lua_getglobal(state, "Region");
|
|
lua_getfield(state, -1, "Create");
|
|
lua_pushlightuserdata(state, *ptr);
|
|
if (lua_pcall(state, 1, 0, 0) != LUA_OK) {
|
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(state, -1) ));
|
|
}
|
|
lua_pop(state, 1);
|
|
}
|
|
|
|
void LuaGenerator::Unload(Region* const ptr) {
|
|
//API hook
|
|
lua_getglobal(state, "Region");
|
|
lua_getfield(state, -1, "Unload");
|
|
lua_pushlightuserdata(state, ptr);
|
|
if (lua_pcall(state, 1, 0, 0) != LUA_OK) {
|
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(state, -1) ));
|
|
}
|
|
lua_pop(state, 1);
|
|
|
|
//clean up the memory
|
|
delete ptr;
|
|
}
|