The basic server map is being displayed in the client
This commit is contained in:
@@ -60,6 +60,9 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
|||||||
disconnectButton.SetText("Disconnect");
|
disconnectButton.SetText("Disconnect");
|
||||||
shutDownButton.SetText("Shut Down");
|
shutDownButton.SetText("Shut Down");
|
||||||
|
|
||||||
|
//load the tilesheet
|
||||||
|
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
||||||
|
|
||||||
//setup the map object
|
//setup the map object
|
||||||
mapPager.SetRegionWidth(REGION_WIDTH);
|
mapPager.SetRegionWidth(REGION_WIDTH);
|
||||||
mapPager.SetRegionHeight(REGION_HEIGHT);
|
mapPager.SetRegionHeight(REGION_HEIGHT);
|
||||||
@@ -132,7 +135,9 @@ void InWorld::FrameEnd() {
|
|||||||
|
|
||||||
void InWorld::Render(SDL_Surface* const screen) {
|
void InWorld::Render(SDL_Surface* const screen) {
|
||||||
//draw the map
|
//draw the map
|
||||||
//TODO
|
ForNearbyRegions([&](Region* const region) {
|
||||||
|
tileSheet.DrawRegionTo(screen, region, camera.x, camera.y);
|
||||||
|
});
|
||||||
|
|
||||||
//draw characters
|
//draw characters
|
||||||
for (auto& it : playerCharacters) {
|
for (auto& it : playerCharacters) {
|
||||||
@@ -291,6 +296,9 @@ void InWorld::HandlePlayerNew(NetworkPacket packet) {
|
|||||||
if (packet.playerInfo.clientIndex == clientIndex && !localCharacter) {
|
if (packet.playerInfo.clientIndex == clientIndex && !localCharacter) {
|
||||||
playerIndex = packet.playerInfo.playerIndex;
|
playerIndex = packet.playerInfo.playerIndex;
|
||||||
localCharacter = &playerCharacters[playerIndex];
|
localCharacter = &playerCharacters[playerIndex];
|
||||||
|
//setup the camera
|
||||||
|
camera.width = GetScreen()->w;
|
||||||
|
camera.height = GetScreen()->h;
|
||||||
//center on the player's character
|
//center on the player's character
|
||||||
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
||||||
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
||||||
@@ -355,8 +363,6 @@ void InWorld::SendState() {
|
|||||||
packet.meta.type = NetworkPacket::Type::PLAYER_UPDATE;
|
packet.meta.type = NetworkPacket::Type::PLAYER_UPDATE;
|
||||||
packet.playerInfo.clientIndex = clientIndex;
|
packet.playerInfo.clientIndex = clientIndex;
|
||||||
packet.playerInfo.playerIndex = playerIndex;
|
packet.playerInfo.playerIndex = playerIndex;
|
||||||
// snprintf(packet.playerInfo.handle, PACKET_STRING_SIZE, "%s", config["player.handle"].c_str());
|
|
||||||
// snprintf(packet.playerInfo.avatar, PACKET_STRING_SIZE, "%s", config["player.avatar"].c_str());
|
|
||||||
packet.playerInfo.position = localCharacter->GetPosition();
|
packet.playerInfo.position = localCharacter->GetPosition();
|
||||||
packet.playerInfo.motion = localCharacter->GetMotion();
|
packet.playerInfo.motion = localCharacter->GetMotion();
|
||||||
|
|
||||||
@@ -386,10 +392,6 @@ void InWorld::RequestShutDown() {
|
|||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::UpdateMap() {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
void InWorld::RequestRegion(int x, int y) {
|
void InWorld::RequestRegion(int x, int y) {
|
||||||
NetworkPacket packet;
|
NetworkPacket packet;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
char buffer[PACKET_BUFFER_SIZE];
|
||||||
@@ -401,3 +403,27 @@ void InWorld::RequestRegion(int x, int y) {
|
|||||||
serialize(&packet, buffer);
|
serialize(&packet, buffer);
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Utilities
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::UpdateMap() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::ForNearbyRegions(std::function<void (Region* const)> func) {
|
||||||
|
//TODO: switch this to "is nearby"
|
||||||
|
//this is ugly
|
||||||
|
for (int i = snapToBase(mapPager.GetRegionWidth() * tileSheet.GetTileW(), camera.x);
|
||||||
|
i < camera.x + camera.width;
|
||||||
|
i += mapPager.GetRegionWidth() * tileSheet.GetTileW()
|
||||||
|
) {
|
||||||
|
for (int j = snapToBase(mapPager.GetRegionHeight() * tileSheet.GetTileH(), camera.y);
|
||||||
|
j < camera.y + camera.height;
|
||||||
|
j += mapPager.GetRegionHeight() * tileSheet.GetTileH()
|
||||||
|
) {
|
||||||
|
func(mapPager.GetRegion(i, j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#include "player_character.hpp"
|
#include "player_character.hpp"
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class InWorld : public BaseScene {
|
class InWorld : public BaseScene {
|
||||||
@@ -80,9 +82,12 @@ protected:
|
|||||||
void SendState();
|
void SendState();
|
||||||
void RequestDisconnect();
|
void RequestDisconnect();
|
||||||
void RequestShutDown();
|
void RequestShutDown();
|
||||||
void UpdateMap();
|
|
||||||
void RequestRegion(int x, int y);
|
void RequestRegion(int x, int y);
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
void UpdateMap();
|
||||||
|
void ForNearbyRegions(std::function<void (Region* const)> func);
|
||||||
|
|
||||||
//globals
|
//globals
|
||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
@@ -91,6 +96,7 @@ protected:
|
|||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
|
TileSheet tileSheet;
|
||||||
|
|
||||||
//map
|
//map
|
||||||
RegionPager<BlankGenerator, DummyFormat> mapPager;
|
RegionPager<BlankGenerator, DummyFormat> mapPager;
|
||||||
@@ -100,6 +106,7 @@ protected:
|
|||||||
Button shutDownButton;
|
Button shutDownButton;
|
||||||
struct {
|
struct {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
|
int width = 0, height = 0;
|
||||||
int marginX = 0, marginY = 0;
|
int marginX = 0, marginY = 0;
|
||||||
} camera;
|
} camera;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ..
|
INCLUDES+=. .. ../map
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|||||||
@@ -34,8 +34,28 @@ void TileSheet::Unload() {
|
|||||||
XCount = YCount = 0;
|
XCount = YCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, int tile) {
|
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
|
||||||
image.SetClipX(tile % XCount * image.GetClipW());
|
//0 is invisible
|
||||||
image.SetClipY(tile / XCount * image.GetClipH());
|
if (tile == 0) return;
|
||||||
|
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
||||||
|
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
||||||
image.DrawTo(dest, x, y);
|
image.DrawTo(dest, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) {
|
||||||
|
Region::type_t tile = 0;
|
||||||
|
for (register int i = 0; i < region->GetWidth(); ++i) {
|
||||||
|
for (register int j = 0; j < region->GetHeight(); ++j) {
|
||||||
|
for (register int k = 0; k < region->GetDepth(); ++k) {
|
||||||
|
tile = region->GetTile(i, j, k);
|
||||||
|
//0 is invisible
|
||||||
|
if (tile == 0) continue;
|
||||||
|
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
||||||
|
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
||||||
|
image.DrawTo(dest,
|
||||||
|
region->GetX() + i * image.GetClipW() - camX,
|
||||||
|
region->GetY() + j * image.GetClipH() - camY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#ifndef TILESHEET_HPP_
|
#ifndef TILESHEET_HPP_
|
||||||
#define TILESHEET_HPP_
|
#define TILESHEET_HPP_
|
||||||
|
|
||||||
|
#include "region.hpp"
|
||||||
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -35,7 +37,8 @@ public:
|
|||||||
void Load(std::string fname, int XCount, int YCount);
|
void Load(std::string fname, int XCount, int YCount);
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, int x, int y, int tile);
|
void DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
|
||||||
|
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
|
||||||
|
|
||||||
//accessors
|
//accessors
|
||||||
Image* GetImage() { return ℑ }
|
Image* GetImage() { return ℑ }
|
||||||
|
|||||||
+10
-3
@@ -61,7 +61,13 @@ EditorScene::EditorScene(ConfigUtility* const arg1):
|
|||||||
pager.SetRegionDepth(REGION_DEPTH);
|
pager.SetRegionDepth(REGION_DEPTH);
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
tsheet.Load(config["dir.tilesets"] + "sand.bmp", 12, 3);
|
tsheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
||||||
|
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||||
|
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
|
pager.SetTile(i, j, 0, 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pager.SetTile(5, 10, 1, 48);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorScene::~EditorScene() {
|
EditorScene::~EditorScene() {
|
||||||
@@ -85,7 +91,8 @@ void EditorScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::Render(SDL_Surface* const screen) {
|
void EditorScene::Render(SDL_Surface* const screen) {
|
||||||
//debug
|
tsheet.DrawRegionTo(screen, pager.GetRegion(0, 0), camera.x, camera.y);
|
||||||
|
/* //debug
|
||||||
for (int i = 0; i < pager.GetRegionWidth()*2; i++) {
|
for (int i = 0; i < pager.GetRegionWidth()*2; i++) {
|
||||||
for (int j = 0; j < pager.GetRegionHeight()*2; j++) {
|
for (int j = 0; j < pager.GetRegionHeight()*2; j++) {
|
||||||
for (int k = 0; k < pager.GetRegionDepth(); k++) {
|
for (int k = 0; k < pager.GetRegionDepth(); k++) {
|
||||||
@@ -99,7 +106,7 @@ void EditorScene::Render(SDL_Surface* const screen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
//draw a big bar across the top (hackish)
|
//draw a big bar across the top (hackish)
|
||||||
buttonImage.SetClipY(0);
|
buttonImage.SetClipY(0);
|
||||||
for (int i = 0; i < screen->w; i += buttonImage.GetClipW()) {
|
for (int i = 0; i < screen->w; i += buttonImage.GetClipW()) {
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ print("Lua script check OK (./rsc)")
|
|||||||
|
|
||||||
function Region.Create(r)
|
function Region.Create(r)
|
||||||
print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")")
|
print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")")
|
||||||
|
for i = 1, Region.GetWidth(r) do
|
||||||
|
for j = 1, Region.GetHeight(r) do
|
||||||
|
if math.abs(i) == math.abs(j) then
|
||||||
|
Region.SetTile(r, i, j, 1, 50)
|
||||||
|
else
|
||||||
|
Region.SetTile(r, i, j, 1, 14)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("done")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Region.Unload(r)
|
function Region.Unload(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user