Compare commits

..

4 Commits

Author SHA1 Message Date
Kayne Ruse 48bec25336 Removed trace statements, moved a couple util files 2015-03-30 22:33:23 +11:00
Kayne Ruse 39f03b2da8 meta-meta table is functioning correctly 2015-03-27 21:54:41 +11:00
Kayne Ruse 9a5c447d0c userdata metatable is loaded smoothly 2015-03-27 20:42:36 +11:00
Kayne Ruse 29ccb982e6 Created userdata metatable 2015-03-27 20:29:16 +11:00
13 changed files with 155 additions and 67 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
## Outline
Tortuga is a 2D MMORPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers.
Tortuga is a 2D multiplayer JRPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers.
This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), as well as more modern sandboxes amd MMOs (Minecraft, EVE Online). This project is currently independently created and funded, with the goal of creating a game that will engage the players and inspire a large community.
+2 -15
View File
@@ -125,16 +125,8 @@ void World::Update() {
it.second.Update();
}
try {
//update the map
UpdateMap();
}
catch(terminal_error& e) {
throw(e);
}
catch(std::exception& e) {
std::cerr << "UpdateMap Error: " << e.what() << std::endl;
}
//update the map
UpdateMap();
//skip the rest without a local character
if (!localCharacter) {
@@ -170,11 +162,6 @@ void World::Render(SDL_Surface* const screen) {
//draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
//debugging
// std::ostringstream msg;
// msg << it->GetX() << ", " << it->GetY();
// font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y);
}
//draw the entities
+1 -40
View File
@@ -23,24 +23,6 @@
#include "channels.hpp"
#include <sstream>
//-------------------------
//static functions
//-------------------------
static int regionChecksum(Region* const region) {
int sum = 0;
for(int i = 0; i < REGION_WIDTH; i++) {
for (int j = 0; j < REGION_HEIGHT; j++) {
for (int k = 0; k < REGION_DEPTH; k++) {
sum += region->GetTile(i, j, k);
}
}
}
return sum;
}
//-------------------------
//map management
//-------------------------
@@ -58,13 +40,6 @@ void World::SendRegionRequest(int roomIndex, int x, int y) {
}
void World::hRegionContent(RegionPacket* const argPacket) {
//checksum
if (regionChecksum(argPacket->region) == 0) {
std::ostringstream msg;
msg << "Received region checksum failed: " << argPacket->x << ", " << argPacket->y;
throw(std::runtime_error(msg.str()));
}
//replace existing regions
regionPager.UnloadIf([&](Region const& region) -> bool {
return region.GetX() == argPacket->x && region.GetY() == argPacket->y;
@@ -96,23 +71,9 @@ void World::UpdateMap() {
//request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
Region* region = regionPager.FindRegion(i, j);
if (!region) {
//request absent region
if (!regionPager.FindRegion(i, j)) {
SendRegionRequest(roomIndex, i, j);
}
else if (regionChecksum(region) == 0) {
//checksum failed
//NOTE: this patches bug #45, but does not resolve it
regionPager.UnloadIf([region](Region const& ref) -> bool {
//remove the erroneous region
return region == &ref;
});
SendRegionRequest(roomIndex, i, j);
std::ostringstream msg;
msg << "Existing region checksum failed: " << roomIndex << ", " << i << ", " << j;
throw(std::runtime_error(msg.str()));
}
}
}
}
-1
View File
@@ -70,7 +70,6 @@ Region* RegionPagerBase::FindRegion(int x, int y) {
}
Region* RegionPagerBase::PushRegion(Region* const ptr) {
//BUG: #45 Some regions are occasionally losing their tile data
regionList.push_front(*ptr);
return &regionList.front();
}
-6
View File
@@ -65,9 +65,6 @@ end
--custom generation systems here
function mapMaker.DebugIsland(r)
--debug
io.write("map_maker:DebugIsland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n")
--basic distance check for each tile, placing an island around the world origin
for i = 1, regionAPI.GetWidth(r) do
for j = 1, regionAPI.GetHeight(r) do
@@ -98,9 +95,6 @@ function mapMaker.DebugIsland(r)
end
function mapMaker.DebugGrassland(r)
--debug
io.write("map_maker:DebugGrassland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n")
--all dirt
for i = 1, regionAPI.GetWidth(r) do
for j = 1, regionAPI.GetHeight(r) do
+2 -2
View File
@@ -4,11 +4,11 @@ local mapSaver = {}
function mapSaver.Load(r)
--empty
-- io.write("map_saver:Load(", region.GetX(r), ", ", region.GetY(r), ")\n")
io.write("map_saver:Load(", region.GetX(r), ", ", region.GetY(r), ")\n")
end
function mapSaver.Save(r)
--empty
-- io.write("map_saver:Save(", region.GetX(r), ", ", region.GetY(r), ")\n")
io.write("map_saver:Save(", region.GetX(r), ", ", region.GetY(r), ")\n")
end
--TODO: (3) create a flexible saving & loading system
+1 -1
View File
@@ -31,6 +31,6 @@ local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bm
roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save)
--call the monstrosity
doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64)
doorUtility.createDoorPair("pair 1", overworld, 0, -64, underworld, 0, 0)
print("Finished the lua script")
-1
View File
@@ -26,7 +26,6 @@
#include <stack>
#include <stdexcept>
//TODO: (9) character collisions should be preformed client-side
void RoomData::RunFrame() {
//get the hook
lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef);
+6
View File
@@ -23,6 +23,7 @@
//utility functions
#include "sql_tools.hpp"
#include "userdata.hpp"
//std & STL
#include <stdexcept>
@@ -78,6 +79,11 @@ void ServerApplication::Init(int argc, char* argv[]) {
std::cout << "Initialized lua" << std::endl;
//create the userdata metatable
createUserdataMetatable(luaState);
std::cout << "\tCreated userdata metatable" << std::endl;
//append config["dir.scripts"] to the module path
if (config["dir.scripts"].size() > 0) {
//get the original path
+113
View File
@@ -0,0 +1,113 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "userdata.hpp"
#define METAMETA "__metameta"
static int index(lua_State* L) {
//get __metameta
lua_getmetatable(L, 1); //get the userdata metatable
lua_pushstring(L, METAMETA); //push the __metameta name
lua_gettable(L, -2); //get the __metameta field from the metatable
//get __metameta[userdata]
lua_pushvalue(L, 1); //copy of the userdata
lua_gettable(L, -2); //get the table at __metameta[userdata]
//table doesn't exist yet
if (lua_isnil(L, -1)) {
return 1;
}
//get the value at __metameta[userdata][key]
lua_pushvalue(L, 2); //copy the key
lua_gettable(L, -2); //get value from the deepest table
//return
return 1;
}
static int newindex(lua_State* L) {
//get __metameta
lua_getmetatable(L, 1); //get the userdata metatable
lua_pushstring(L, METAMETA); //push the __metameta name
lua_gettable(L, -2); //get the __metameta field from the metatable
//get __metameta[userdata]
lua_pushvalue(L, 1); //copy of the userdata
lua_gettable(L, -2); //get the table at __metameta[userdata]
//if this table doesn't exist yet
if (lua_isnil(L, -1)) {
lua_pop(L, 1); //pop nil
lua_pushvalue(L, 1); //copy userdata (key)
lua_createtable(L, 0, 0); //new table (value)
lua_settable(L, -3); //create the new table in __metameta
lua_pushvalue(L, 1); //copy userdata (key)
lua_gettable(L, -2); //get the newly created table
}
//set the value at __metameta[userdata][key] = value
lua_pushvalue(L, 2); //copy the key
lua_pushvalue(L, 3); //copy the value
lua_settable(L, -3); //set value in the deepest table
//return
return 0;
}
static luaL_Reg metatable[] = {
{"__index", index},
{"__newindex", newindex},
{nullptr, nullptr}
};
int createUserdataMetatable(lua_State* L) {
//create the userdata metatable
lua_pushlightuserdata(L, nullptr); //anon userdata
lua_createtable(L, 0, 0); //table
//insert meta-metatable
lua_pushstring(L, METAMETA);
lua_createtable(L, 0, 0);
lua_settable(L, -3);
//insert metatable blocker
lua_pushstring(L, "__metatable");
lua_createtable(L, 0, 0);
lua_settable(L, -3);
//insert metamethods
for (luaL_Reg* it = metatable; it->name; it++) {
lua_pushstring(L, it->name);
lua_pushcfunction(L, it->func);
lua_settable(L, -3);
}
//set in the object & pop the anon userdata
lua_setmetatable(L, -2); //set the metatable for userdata
lua_pop(L, 1); //pop the anon userdata
return 0;
}
+29
View File
@@ -0,0 +1,29 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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.
*/
#ifndef METATABLES_HPP_
#define METATABLES_HPP_
#include "lua.hpp"
int createUserdataMetatable(lua_State* L);
#endif