Merge branch 'develop'
This commit is contained in:
@@ -137,12 +137,18 @@ void ClientApplication::Proc() {
|
|||||||
realTime = Clock::now();
|
realTime = Clock::now();
|
||||||
|
|
||||||
//simulate game time
|
//simulate game time
|
||||||
|
if (simTime < realTime) {
|
||||||
while (simTime < realTime) {
|
while (simTime < realTime) {
|
||||||
//call each user defined function
|
//call each user defined function
|
||||||
activeScene->RunFrame();
|
activeScene->RunFrame();
|
||||||
//~60 FPS
|
//~60 FPS
|
||||||
simTime += std::chrono::duration<int, std::milli>(16);
|
simTime += std::chrono::duration<int, std::milli>(16);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//give the machine a break
|
||||||
|
SDL_Delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
//draw the game to the screen
|
//draw the game to the screen
|
||||||
activeScene->RenderFrame();
|
activeScene->RenderFrame();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../entities ../monsters ../server_utilities ../waypoints ../../common/map ../../common/utilities
|
INCLUDES+=. ../characters ../entities ../monsters ../server_utilities ../waypoints ../../common/gameplay ../../common/map ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,6 @@ WaypointManager* RoomData::GetWaypointMgr() {
|
|||||||
return &waypointMgr;
|
return &waypointMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Entity*>* RoomData::GetEntityList() {
|
std::list<CharacterData*>* RoomData::GetCharacterList() {
|
||||||
return &entityList;
|
return &characterList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifndef ROOMDATA_HPP_
|
#ifndef ROOMDATA_HPP_
|
||||||
#define ROOMDATA_HPP_
|
#define ROOMDATA_HPP_
|
||||||
|
|
||||||
#include "entity.hpp"
|
#include "character_data.hpp"
|
||||||
#include "monster_manager.hpp"
|
#include "monster_manager.hpp"
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "waypoint_manager.hpp"
|
#include "waypoint_manager.hpp"
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
RegionPagerLua* GetPager();
|
RegionPagerLua* GetPager();
|
||||||
MonsterManager* GetMonsterMgr();
|
MonsterManager* GetMonsterMgr();
|
||||||
WaypointManager* GetWaypointMgr();
|
WaypointManager* GetWaypointMgr();
|
||||||
std::list<Entity*>* GetEntityList();
|
std::list<CharacterData*>* GetCharacterList();
|
||||||
|
|
||||||
//TODO: triggers for unload, save, per-second, player enter, player exit, etc.
|
//TODO: triggers for unload, save, per-second, player enter, player exit, etc.
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ private:
|
|||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
MonsterManager monsterMgr;
|
MonsterManager monsterMgr;
|
||||||
WaypointManager waypointMgr;
|
WaypointManager waypointMgr;
|
||||||
std::list<Entity*> entityList;
|
std::list<CharacterData*> characterList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -60,34 +60,34 @@ void RoomManager::UnloadIf(std::function<bool(std::pair<const int, RoomData cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomManager::PushEntity(Entity* entity) {
|
void RoomManager::PushCharacter(CharacterData* character) {
|
||||||
if (!entity) {
|
if (!character) {
|
||||||
throw(std::runtime_error("Failed to push a null entity to a room"));
|
throw(std::runtime_error("Failed to push a null character to a room"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* room = Get(entity->GetRoomIndex());
|
RoomData* room = Get(character->GetRoomIndex());
|
||||||
|
|
||||||
if (!room) {
|
if (!room) {
|
||||||
throw(std::runtime_error("Failed to push an entity to a non-existant room"));
|
throw(std::runtime_error("Failed to push an character to a non-existant room"));
|
||||||
}
|
}
|
||||||
|
|
||||||
room->entityList.push_back(entity);
|
room->characterList.push_back(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomManager::PopEntity(Entity const* entity) {
|
void RoomManager::PopCharacter(CharacterData const* character) {
|
||||||
//NOTE: to pop an entity from a room, the entity must first exist
|
//NOTE: to pop an character from a room, the character must first exist
|
||||||
if (!entity) {
|
if (!character) {
|
||||||
throw(std::runtime_error("Failed to pop a null entity to a room"));
|
throw(std::runtime_error("Failed to pop a null character to a room"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* room = Get(entity->GetRoomIndex());
|
RoomData* room = Get(character->GetRoomIndex());
|
||||||
|
|
||||||
if (!room) {
|
if (!room) {
|
||||||
throw(std::runtime_error("Failed to pop an entity to a non-existant room"));
|
throw(std::runtime_error("Failed to pop an character to a non-existant room"));
|
||||||
}
|
}
|
||||||
|
|
||||||
room->entityList.remove_if([entity](Entity* ptr) {
|
room->characterList.remove_if([character](CharacterData* ptr) {
|
||||||
return entity == ptr;
|
return character == ptr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifndef ROOMMANAGER_HPP_
|
#ifndef ROOMMANAGER_HPP_
|
||||||
#define ROOMMANAGER_HPP_
|
#define ROOMMANAGER_HPP_
|
||||||
|
|
||||||
#include "entity.hpp"
|
#include "character_data.hpp"
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
@@ -40,8 +40,8 @@ public:
|
|||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
||||||
|
|
||||||
void PushEntity(Entity* entity);
|
void PushCharacter(CharacterData* character);
|
||||||
void PopEntity(Entity const* entity);
|
void PopCharacter(CharacterData const* character);
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
RoomData* Get(int uid);
|
RoomData* Get(int uid);
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ private:
|
|||||||
|
|
||||||
//utility methods
|
//utility methods
|
||||||
void PumpPacket(SerialPacket* const);
|
void PumpPacket(SerialPacket* const);
|
||||||
|
void PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance);
|
||||||
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
void CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex);
|
||||||
|
|
||||||
//APIs and utilities
|
//APIs and utilities
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//push to the rooms
|
//push to the rooms
|
||||||
roomMgr.PushEntity(characterMgr.Get(characterIndex));
|
roomMgr.PushCharacter(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
@@ -90,7 +90,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//pop from the rooms
|
//pop from the rooms
|
||||||
roomMgr.PopEntity(characterMgr.Get(characterIndex));
|
roomMgr.PopCharacter(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//delete the character
|
//delete the character
|
||||||
characterMgr.Delete(characterIndex);
|
characterMgr.Delete(characterIndex);
|
||||||
@@ -126,7 +126,7 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//push to the rooms
|
//push to the rooms
|
||||||
roomMgr.PushEntity(characterMgr.Get(characterIndex));
|
roomMgr.PushCharacter(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
@@ -159,7 +159,7 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//pop from the rooms
|
//pop from the rooms
|
||||||
roomMgr.PopEntity(characterData);
|
roomMgr.PopCharacter(characterData);
|
||||||
|
|
||||||
//unload the character
|
//unload the character
|
||||||
characterMgr.Unload(argPacket->characterIndex);
|
characterMgr.Unload(argPacket->characterIndex);
|
||||||
@@ -203,7 +203,7 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//pop from the old room
|
//pop from the old room
|
||||||
roomMgr.PopEntity(characterData);
|
roomMgr.PopCharacter(characterData);
|
||||||
|
|
||||||
//set the character's room, zero it's origin, zero it's motion
|
//set the character's room, zero it's origin, zero it's motion
|
||||||
characterData->SetRoomIndex(argPacket->roomIndex);
|
characterData->SetRoomIndex(argPacket->roomIndex);
|
||||||
@@ -211,7 +211,7 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
|
|||||||
characterData->SetMotion({0, 0});
|
characterData->SetMotion({0, 0});
|
||||||
|
|
||||||
//push to the new room
|
//push to the new room
|
||||||
roomMgr.PushEntity(characterData);
|
roomMgr.PushCharacter(characterData);
|
||||||
|
|
||||||
//update the clients
|
//update the clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
@@ -300,5 +300,5 @@ void ServerApplication::HandleCharacterSetMotion(CharacterPacket* const argPacke
|
|||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||||
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
|
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
|
||||||
PumpPacket(&newPacket);
|
PumpPacketProximity(&newPacket, characterData->GetRoomIndex(), characterData->GetOrigin(), -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ void ServerApplication::Proc() {
|
|||||||
std::cerr << "Client dropped: " << disconnected << std::endl;
|
std::cerr << "Client dropped: " << disconnected << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//give the computer a break
|
//give the machine a break
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
delete reinterpret_cast<char*>(packetBuffer);
|
delete reinterpret_cast<char*>(packetBuffer);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ void ServerApplication::FullCharacterUnload(int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//pop from the rooms
|
//pop from the rooms
|
||||||
roomMgr.PopEntity(&character.second);
|
roomMgr.PopCharacter(&character.second);
|
||||||
|
|
||||||
//pump character unload
|
//pump character unload
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
@@ -175,6 +175,22 @@ void ServerApplication::PumpPacket(SerialPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerApplication::PumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) {
|
||||||
|
RoomData* room = roomMgr.Get(roomIndex);
|
||||||
|
|
||||||
|
if (!room) {
|
||||||
|
throw(std::runtime_error("Failed to pump to a non-existant room"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& character : *room->GetCharacterList()) {
|
||||||
|
if (distance == -1 || (character->GetOrigin() - position).Length() <= distance) {
|
||||||
|
AccountData* account = accountMgr.Get(character->GetOwner());
|
||||||
|
ClientData* client = clientMgr.Get(account->GetClientIndex());
|
||||||
|
network.SendTo(client->GetAddress(), argPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
|
||||||
CharacterData* character = characterMgr.Get(characterIndex);
|
CharacterData* character = characterMgr.Get(characterIndex);
|
||||||
if (!character) {
|
if (!character) {
|
||||||
|
|||||||
@@ -18,3 +18,4 @@ TODO: The TileSheet class should implement the surface itself
|
|||||||
TODO: Time delay for requesting region packets
|
TODO: Time delay for requesting region packets
|
||||||
TODO: A proper logging system
|
TODO: A proper logging system
|
||||||
TODO: Fix the const-ness of accessors
|
TODO: Fix the const-ness of accessors
|
||||||
|
TODO: Add a screenshot of the game to README.md
|
||||||
Reference in New Issue
Block a user