Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nemerle committed Nov 1, 2018
2 parents 8ddd827 + 2d4207d commit 6d5b16a
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rd_party/Lutefisk3D"]
path = 3rd_party/Lutefisk3D
url = https://github.com/Lutefisk3D/lutefisk3d
13 changes: 6 additions & 7 deletions 3rd_party/ExternalProject_Lutefisk3D.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Lutefisk3D/CMake/LutefiskOptions.cmake")
message(FATAL_ERROR "Lutefisk3D git submodule has not been checked out.")
endif()
if(FALSE)
set(LUTEFISK3D_NETWORK OFF) # don't need it, and it doesn't compile anyway :)
add_subdirectory(Lute)
add_subdirectory(Lutefisk3D)
else()
#NOTE: by default lutefisk builds in RelWithDebInfo
# for our use case this seems the most optimal build type.
libname(lutefisk3d Lutefisk3D)
# add the main options for lutefisk,
# NOTE: this only works when Lutefisk is aleady checked-out submodule
# this will likely happen, but not just yet.
#include(${CMAKE_CURRENT_SOURCE_DIR}/Lute/CMake/LutefiskOptions.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/Lutefisk3D/CMake/LutefiskOptions.cmake)
set(LUTEFISK3D_NETWORK OFF) # don't need it, and it doesn't compile anyway :)

set(lutefisk_cmake_options
Expand All @@ -30,9 +31,7 @@ else()

ExternalProject_Add(
l3d_BUILD
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Lute
GIT_REPOSITORY https://github.com/Lutefisk3D/lutefisk3d
GIT_SHALLOW 1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Lutefisk3D
UPDATE_COMMAND ""
INSTALL_DIR ${ThirdParty_Install_Dir}
CMAKE_ARGS ${lutefisk_cmake_options}
Expand Down
1 change: 1 addition & 0 deletions 3rd_party/Lutefisk3D
Submodule Lutefisk3D added at 75576e
12 changes: 11 additions & 1 deletion Components/serialization_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ inline void prologue(JSONInputArchive &, QString const &) { }
inline void prologue(BinaryOutputArchive &, QString const &) { }
inline void prologue(BinaryInputArchive &, QString const &) { }

inline void epilogue(BinaryOutputArchive &, QByteArray const &) { }
inline void epilogue(BinaryInputArchive &, QByteArray const &) { }
inline void epilogue(JSONOutputArchive &, QByteArray const &) { }
inline void epilogue(JSONInputArchive &, QByteArray const &) { }

inline void prologue(JSONOutputArchive &, QByteArray const &) { }
inline void prologue(JSONInputArchive &, QByteArray const &) { }
inline void prologue(BinaryOutputArchive &, QByteArray const &) { }
inline void prologue(BinaryInputArchive &, QByteArray const &) { }

template<class Archive>
inline void CEREAL_SAVE_FUNCTION_NAME(Archive & ar, ::QString const & str)
{
Expand All @@ -50,7 +60,7 @@ inline void CEREAL_SAVE_FUNCTION_NAME(Archive & ar, ::QString const & str)
template<class Archive>
inline void CEREAL_SAVE_FUNCTION_NAME(Archive & ar, ::QByteArray const & str)
{
// make sure we actually have a latin1 string in str
// make sure we actually have a latin1 string in str, and not something that has strange ascii chars
assert(QString(str).toLatin1()==str);
ar( str.toStdString() );
}
Expand Down
11 changes: 11 additions & 0 deletions Projects/CoX/Common/GameData/CommonNetStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ class ColorAndPartPacker
virtual void packPartname(const QString &c,BitStream &into) const =0;
virtual void unpackPartname(BitStream &from,QString &tgt) const =0;
};
///
/// \brief The IndexedStringPacker class is responsible for storing a mapping from string to index
/// So when sending a new string to the client, the contents can be sent only once, and afterwards the index is used instead.
///
class IndexedStringPacker
{
public:
virtual void addString(const QString &) = 0;
/// return index of a string, or 0 if the string has not been added yet.
virtual int getIndex(const QString &) const =0;
};
extern void storeBitsConditional(BitStream &bs, uint8_t numbits, int bits);
extern int getBitsConditional(BitStream &bs, uint32_t numbits);
extern void storePackedBitsConditional(BitStream &bs, uint8_t numbits, int bits);
Expand Down
61 changes: 58 additions & 3 deletions Projects/CoX/Common/GameData/GameDataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
#include "Common/GameData/charclass_serializers.h"
#include "Common/GameData/keybind_serializers.h"
#include "Common/GameData/npc_serializers.h"
#include "Common/GameData/fx_definitions.h"
#include "Common/GameData/fx_serializers.h"
#include "Common/GameData/power_serializers.h"
#include "Common/GameData/trick_serializers.h"
#include "Common/GameData/CommonNetStructures.h"
#include "Logging.h"
#include "Settings.h"

#include <QtCore/QDebug>
#include <QtCore/QString>


namespace
Expand All @@ -37,6 +40,40 @@ uint32_t color_to_4ub(const glm::vec3 &rgb)
{
return ((uint32_t)rgb[0]) | (((uint32_t)rgb[1])<<8) | (((uint32_t)rgb[2])<<16) | (0xFFu<<24);
}
class IndexedPacker final : public IndexedStringPacker
{
std::vector<QString> m_known_strings;
QHash<QString,int> m_string_to_index;

public:
void sortEntries() {
std::sort(m_known_strings.begin(),m_known_strings.end(),[](const QString &a,const QString &b)->bool {
// all added strings have been lower-cased, so no need to case-insensitive compare here.
return a.compare(b)<0;
});
// record the new order in map.
int i=1;
for(const QString &str : m_known_strings)
m_string_to_index[str] = i++;
}

// IndexedStringPacker interface
void addString(const QString &str)
{
int idx = m_string_to_index.value(str.toLower(),0);
if(idx)
{
assert(0==m_known_strings[idx-1].compare(str,Qt::CaseInsensitive));
return;
}
m_known_strings.push_back(str.toLower());
m_string_to_index[str.toLower()] = m_known_strings.size();
}
int getIndex(const QString &str) const
{
return m_string_to_index.value(str.toLower(),0);
}
};

class HashBasedPacker final : public ColorAndPartPacker
{
Expand All @@ -49,7 +86,6 @@ class HashBasedPacker final : public ColorAndPartPacker
uint32_t color=color_to_4ub(idx.color);
m_colors.insert_entry(color,color);
}

}
public:
~HashBasedPacker() = default;
Expand Down Expand Up @@ -216,17 +252,21 @@ GameDataStore::GameDataStore()
qCritical() << "Multiple instances of GameDataStore created in a single process, expect trouble";
}
packer_instance = new HashBasedPacker;
m_index_based_packer = new IndexedPacker;
}

GameDataStore::~GameDataStore()
{
delete (HashBasedPacker *)packer_instance;
delete (IndexedPacker *)m_index_based_packer;
packer_instance = nullptr;
}

bool GameDataStore::read_game_data(const QString &directory_path)
{
qInfo().noquote() << "Reading game data from" << directory_path << "folder";
QElapsedTimer load_timer;
load_timer.start();

if (!read_costumes(directory_path))
return false;
Expand Down Expand Up @@ -254,11 +294,19 @@ bool GameDataStore::read_game_data(const QString &directory_path)
return false;
if(!read_pi_schedule(directory_path))
return false;
qInfo().noquote() << "Finished reading game data.";
if(!read_fx(directory_path))
return false;
qInfo().noquote() << "Finished reading game data: done in"<<float(load_timer.elapsed())/1000.0f<<"s";
{
TIMED_LOG({
static_cast<HashBasedPacker *>(packer_instance)->fill_hashes(*this);
m_npc_store.prepare_dictionaries();
auto packer = static_cast<IndexedPacker *>(m_index_based_packer);
for(const FxInfo &fx : m_fx_infos)
{
packer->addString(fx.fxname);
}
packer->sortEntries();
},"Postprocessing runtime data .. ");

}
Expand Down Expand Up @@ -471,7 +519,14 @@ bool GameDataStore::read_pi_schedule(const QString &directory_path)
{
qDebug() << "Loading PI Schedule:";
return read_data_to<Parse_PI_Schedule, pischedule_i0_requiredCrc>(directory_path, "bin/schedules.bin",
m_pi_schedule);
m_pi_schedule);
}

bool GameDataStore::read_fx(const QString &directory_path)
{
qDebug() << "Loading FX Information:";
return read_data_to<std::vector<struct FxInfo>, fxinfos_i0_requiredCrc>(directory_path, "bin/fxinfo.bin",
m_fx_infos);
}

const Parse_PowerSet& GameDataStore::get_powerset(uint32_t pcat_idx, uint32_t pset_idx)
Expand Down
8 changes: 6 additions & 2 deletions Projects/CoX/Common/GameData/GameDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include "NpcStore.h"

class ColorAndPartPacker;
class IndexedStringPacker;
class QString;
class GameDataStore
{
ColorAndPartPacker *packer_instance = nullptr;
LevelExpAndDebt m_experience_and_debt_per_level;
ColorAndPartPacker * packer_instance = nullptr;
IndexedStringPacker *m_index_based_packer = nullptr;
LevelExpAndDebt m_experience_and_debt_per_level;

bool read_costumes(const QString &directory_path);
bool read_colors(const QString &src_filename);
Expand All @@ -38,6 +40,7 @@ class GameDataStore
bool read_combine_chances(const QString &directory_path);
bool read_effectiveness(const QString &directory_path);
bool read_pi_schedule(const QString &directory_path);
bool read_fx(const QString &directory_path);
public:
GameDataStore();
~GameDataStore();
Expand Down Expand Up @@ -66,6 +69,7 @@ class GameDataStore
Parse_Effectiveness m_effectiveness_above;
Parse_Effectiveness m_effectiveness_below;
Parse_PI_Schedule m_pi_schedule;
std::vector<struct FxInfo> m_fx_infos;
float m_player_fade_in;

// keep in mind the hierarchy is all_powers -> powercat -> powerset -> powerdata (template)
Expand Down
7 changes: 7 additions & 0 deletions Projects/CoX/Common/Runtime/Prefab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,10 @@ GeoStoreDef * PrefabStore::groupGetFileEntryPtr(const QString &full_name)
key = key.mid(0, key.indexOf("__"));
return m_modelname_to_geostore.value(key, nullptr);
}
void PrefabStore::sceneGraphWasReset()
{
for(auto & v : m_dir_to_geoset)
{
v.loaded = false;
}
}
1 change: 1 addition & 0 deletions Projects/CoX/Common/Runtime/Prefab.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct PrefabStore
bool loadNamedPrefab(const QString &name, LoadingContext &conv);
Model *groupModelFind(const QString &path, LoadingContext &ctx);
GeoStoreDef * groupGetFileEntryPtr(const QString &full_name);
void sceneGraphWasReset(); // reset 'loaded' flag on all geostores
};

} // namespace SEGS
11 changes: 7 additions & 4 deletions Projects/CoX/Common/Runtime/SceneGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SceneNode * getNodeByName(const SceneGraph &graph,const QString &name)
filename = name;
else
filename = name.mid(idx+1);
return graph.name_to_node.value(filename.toLower(),nullptr);
return graph.name_to_node.value(filename.toLower(), nullptr);
}

}
Expand Down Expand Up @@ -219,6 +219,7 @@ SceneNode *newDef(SceneGraph &scene)
SceneNode *res = new SceneNode;
res->m_index_in_scenegraph = scene.all_converted_defs.size();
scene.all_converted_defs.emplace_back(res);
res->in_use = true;
return res;
}
void setNodeNameAndPath(SceneGraph &scene,SceneNode *node, QString obj_path)
Expand All @@ -235,9 +236,9 @@ void setNodeNameAndPath(SceneGraph &scene,SceneNode *node, QString obj_path)
QString lowkey = key.toString().toLower();
auto iter = scene.name_to_node.find(lowkey);
if(iter==scene.name_to_node.end()) {
iter=scene.name_to_node.insert(lowkey,node);
scene.name_to_node[lowkey] = node;
}
node->name = iter.key();
node->name = key.toString();
node->dir.clear();
if ( key.position() != 0 )
node->dir = result.mid(0,key.position()-1);
Expand All @@ -254,7 +255,8 @@ void addChildNodes(const SceneGraphNode_Data &inp_data, SceneNode *node, Loading
child.node = getNodeByName(*ctx.m_target,new_name);
if ( !child.node )
{
store.loadNamedPrefab(new_name,ctx);
bool loaded=store.loadNamedPrefab(new_name,ctx);
assert(loaded);
child.node = getNodeByName(*ctx.m_target,new_name);
}
// construct from euler angles
Expand Down Expand Up @@ -546,6 +548,7 @@ SceneGraph *loadWholeMap(const QString &filename)
QString upcase_city = filename;
upcase_city.replace("city","City");
upcase_city.replace("zones","Zones");
rd.m_prefab_mapping->sceneGraphWasReset();
bool res = loadSceneGraph(upcase_city.mid(maps_idx), ctx, *rd.m_prefab_mapping);
if (!res)
{
Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once
#define ProjectName "SEGS"
#define VersionNumber "0.6.0"
#define VersionNumber "0.6.1"
#define VersionName "Outbreak"
#define VersionString ProjectName " v" VersionNumber " (" VersionName ")"
#define CopyrightString "Super Entity Game Server\nhttp://github.com/Segs/\nCopyright (c) 2006-2018 Super Entity Game Server Team (see AUTHORS.md)\nThis software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.\n";
Expand Down

0 comments on commit 6d5b16a

Please sign in to comment.