Merge branch 'develop'
This commit is contained in:
@@ -71,7 +71,7 @@ InWorld::InWorld(
|
|||||||
//load the tilesheet
|
//load the tilesheet
|
||||||
//TODO: add the tilesheet to the map system?
|
//TODO: add the tilesheet to the map system?
|
||||||
//TODO: Tile size and tile sheet should be loaded elsewhere
|
//TODO: Tile size and tile sheet should be loaded elsewhere
|
||||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 32, 32);
|
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
|
||||||
|
|
||||||
//send this player's character info
|
//send this player's character info
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
@@ -0,0 +1,37 @@
|
|||||||
|
local mapMaker = {}
|
||||||
|
|
||||||
|
--utility functions
|
||||||
|
function mapMaker.sqr(x) return x*x end
|
||||||
|
function mapMaker.dist(x, y, i, j) return math.sqrt(mapMaker.sqr(x - i) + mapMaker.sqr(y - j)) end
|
||||||
|
|
||||||
|
--tile macros, mapped to the tilesheet "overworld.bmp"
|
||||||
|
mapMaker.edges = {}
|
||||||
|
mapMaker.edges.north = -16
|
||||||
|
mapMaker.edges.south = 16
|
||||||
|
mapMaker.edges.east = 1
|
||||||
|
mapMaker.edges.west = -1
|
||||||
|
|
||||||
|
mapMaker.water = 18 + 3 * 0
|
||||||
|
mapMaker.sand = 18 + 3 * 1
|
||||||
|
mapMaker.plains = 18 + 3 * 2
|
||||||
|
mapMaker.grass = 18 + 3 * 3
|
||||||
|
mapMaker.dirt = 18 + 3 * 4
|
||||||
|
|
||||||
|
--custom generation systems here
|
||||||
|
function mapMaker.debugIsland(region)
|
||||||
|
for i = 1, Region.GetWidth(region) do
|
||||||
|
for j = 1, Region.GetHeight(region) do
|
||||||
|
local dist = mapMaker.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
||||||
|
if dist < 10 then
|
||||||
|
Region.SetTile(region, i, j, 1, mapMaker.plains)
|
||||||
|
elseif dist < 12 then
|
||||||
|
Region.SetTile(region, i, j, 1, mapMaker.sand)
|
||||||
|
else
|
||||||
|
Region.SetTile(region, i, j, 1, mapMaker.water)
|
||||||
|
Region.SetSolid(region, i, j, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return mapMaker
|
||||||
@@ -1,52 +1,12 @@
|
|||||||
print("Lua script check")
|
print("Lua script check")
|
||||||
|
|
||||||
--uber lazy declarations
|
mapMaker = require "map_maker"
|
||||||
function math.sqr(x) return x*x end
|
mapSaver = require "map_saver"
|
||||||
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
|
||||||
|
|
||||||
--tile macros, mapped to the tilesheet
|
|
||||||
local base = 14
|
|
||||||
local shift = 36
|
|
||||||
tiles = {
|
|
||||||
plains = base + shift * 0,
|
|
||||||
grass = base + shift * 1,
|
|
||||||
dirt = base + shift * 2,
|
|
||||||
sand = base + shift * 3,
|
|
||||||
water = base + shift * 4
|
|
||||||
}
|
|
||||||
|
|
||||||
--custom generation systems here
|
|
||||||
function islandGenerator(region)
|
|
||||||
-- io.write("Generating (", Region.GetX(region), ", ", Region.GetY(region), ")\n")
|
|
||||||
for i = 1, Region.GetWidth(region) do
|
|
||||||
for j = 1, Region.GetHeight(region) do
|
|
||||||
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
|
||||||
if dist < 10 then
|
|
||||||
Region.SetTile(region, i, j, 1, tiles.plains)
|
|
||||||
elseif dist < 12 then
|
|
||||||
Region.SetTile(region, i, j, 1, tiles.sand)
|
|
||||||
else
|
|
||||||
Region.SetTile(region, i, j, 1, tiles.water)
|
|
||||||
Region.SetSolid(region, i, j, true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Get some regions
|
|
||||||
--BUG: #35 The server fails without at least one room
|
--BUG: #35 The server fails without at least one room
|
||||||
--TODO: Create rooms with names?
|
--TODO: Create rooms with names?
|
||||||
newRoom = RoomManager.CreateRoom()
|
newRoom = RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||||
pager = Room.GetPager(newRoom)
|
pager = Room.GetPager(newRoom)
|
||||||
RegionPager.SetOnCreate(pager, islandGenerator)
|
RegionPager.SetOnCreate(pager, mapMaker.debugIsland)
|
||||||
|
|
||||||
--[[
|
|
||||||
regionTable = {
|
|
||||||
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() * 0),
|
|
||||||
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() * 0),
|
|
||||||
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() *-1),
|
|
||||||
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1)
|
|
||||||
}
|
|
||||||
]]
|
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
//map system
|
//map system
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class RoomData {
|
class RoomData {
|
||||||
public:
|
public:
|
||||||
RoomData() = default;
|
RoomData() = default;
|
||||||
@@ -33,11 +35,15 @@ public:
|
|||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
RegionPagerLua* GetPager() { return &pager; }
|
RegionPagerLua* GetPager() { return &pager; }
|
||||||
|
|
||||||
|
std::string SetTilesetName(std::string s) { return tilesetName = s; }
|
||||||
|
std::string GetTilesetName() { return tilesetName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class RoomManager;
|
friend class RoomManager;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
|
std::string tilesetName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ private:
|
|||||||
void HandleSynchronize(ClientPacket* const);
|
void HandleSynchronize(ClientPacket* const);
|
||||||
|
|
||||||
//utility methods
|
//utility methods
|
||||||
|
void CheckClientConnections();
|
||||||
//TODO: a function that only sends to characters in a certain proximity
|
//TODO: a function that only sends to characters in a certain proximity
|
||||||
void CleanupLostConnection(int index);
|
void CleanupLostConnection(int index);
|
||||||
void PumpPacket(SerialPacket* const);
|
void PumpPacket(SerialPacket* const);
|
||||||
|
|||||||
+21
-16
@@ -28,6 +28,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -71,8 +72,27 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
throw(std::runtime_error("Failed to initialize lua"));
|
throw(std::runtime_error("Failed to initialize lua"));
|
||||||
}
|
}
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
|
|
||||||
std::cout << "Initialized lua" << std::endl;
|
std::cout << "Initialized lua" << std::endl;
|
||||||
|
|
||||||
|
//append config["dir.scripts"] to the module path
|
||||||
|
if (config["dir.scripts"].size() > 0) {
|
||||||
|
//get the original path
|
||||||
|
lua_getglobal(luaState, "package");
|
||||||
|
lua_getfield(luaState, -1, "path");
|
||||||
|
|
||||||
|
//build & push the message
|
||||||
|
std::ostringstream path;
|
||||||
|
path << lua_tostring(luaState, -1) << ";" << config["dir.scripts"] << "?.lua";
|
||||||
|
lua_pushstring(luaState, path.str().c_str());
|
||||||
|
|
||||||
|
//set the new path and clean up the stack
|
||||||
|
lua_setfield(luaState, -3, "path");
|
||||||
|
lua_pop(luaState, 2);
|
||||||
|
|
||||||
|
std::cout << "\tLua script directory appended" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Setup the objects
|
//Setup the objects
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -148,23 +168,8 @@ void ServerApplication::Proc() {
|
|||||||
//update the internals
|
//update the internals
|
||||||
//...
|
//...
|
||||||
|
|
||||||
//TODO: This could be checked only every few seconds
|
|
||||||
//Check connections
|
//Check connections
|
||||||
for (auto& it : clientMap) {
|
CheckClientConnections();
|
||||||
if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) {
|
|
||||||
ServerPacket newPacket;
|
|
||||||
newPacket.type = SerialPacketType::PING;
|
|
||||||
network.SendTo(it.second.GetAddress(), &newPacket);
|
|
||||||
it.second.IncrementAttempts();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.second.GetAttempts() > 2) {
|
|
||||||
CleanupLostConnection(it.first);
|
|
||||||
|
|
||||||
//all iterators are invalid, so we can't continue
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//give the computer a break
|
//give the computer a break
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -159,6 +160,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
|||||||
newPacket.x = argPacket->x;
|
newPacket.x = argPacket->x;
|
||||||
newPacket.y = argPacket->y;
|
newPacket.y = argPacket->y;
|
||||||
|
|
||||||
|
//BUG: possibly related to #35
|
||||||
newPacket.region = roomMgr.GetRoom(argPacket->roomIndex)->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
newPacket.region = roomMgr.GetRoom(argPacket->roomIndex)->GetPager()->GetRegion(argPacket->x, argPacket->y);
|
||||||
|
|
||||||
//send the content
|
//send the content
|
||||||
@@ -280,6 +282,23 @@ void ServerApplication::HandleSynchronize(ClientPacket* const argPacket) {
|
|||||||
//utility methods
|
//utility methods
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
void ServerApplication::CheckClientConnections() {
|
||||||
|
for (auto& it : clientMap) {
|
||||||
|
if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PING;
|
||||||
|
network.SendTo(it.second.GetAddress(), &newPacket);
|
||||||
|
it.second.IncrementAttempts();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it.second.GetAttempts() > 2) {
|
||||||
|
CleanupLostConnection(it.first);
|
||||||
|
//all iterators are invalid, so we can't continue
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServerApplication::CleanupLostConnection(int clientIndex) {
|
void ServerApplication::CleanupLostConnection(int clientIndex) {
|
||||||
//NOTE: This assumes each player has only one account and character at a time
|
//NOTE: This assumes each player has only one account and character at a time
|
||||||
//TODO: handle multiple characters (bots, etc.)
|
//TODO: handle multiple characters (bots, etc.)
|
||||||
|
|||||||
Reference in New Issue
Block a user