Skip to content

Commit

Permalink
fix #4929: creg
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Aug 9, 2015
1 parent 0b8be3b commit 7dca29a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 79 deletions.
55 changes: 21 additions & 34 deletions rts/Sim/Misc/LosHandler.cpp
Expand Up @@ -15,40 +15,27 @@
#include "System/TimeProfiler.h"


CR_BIND(SLosInstance, (0, 0, int2(), 0.f, 0))
CR_BIND(ILosType, (0, LOS_TYPE_LOS))
CR_BIND(ILosType::DelayedInstance, )
CR_BIND(CLosHandler, )


//CR_REG_METADATA(ILosType,(
//FIXME
//))
CR_REG_METADATA(SLosInstance, (
CR_IGNORED(squares),
CR_MEMBER(radius),
CR_MEMBER(refCount),
CR_MEMBER(allyteam),
CR_MEMBER(basePos),
CR_MEMBER(hashNum),
CR_MEMBER(baseHeight),
CR_MEMBER(toBeDeleted),
CR_MEMBER(needsRecalc)
))
CR_REG_METADATA_SUB(ILosType, DelayedInstance, (
CR_MEMBER(instance),
CR_MEMBER(timeoutTime)))


// ILosTypes aren't creg'ed cause they repopulate themselves in case of loading a saved game
CR_REG_METADATA(CLosHandler,(
CR_MEMBER(los),
CR_MEMBER(airLos),
CR_MEMBER(radar),
CR_MEMBER(sonar),
CR_MEMBER(commonJammer),
CR_MEMBER(commonSonarJammer),
CR_MEMBER(seismic),
CR_MEMBER(radarErrorSizes)
CR_IGNORED(autoLinkEvents),
CR_IGNORED(autoLinkedEvents),
CR_IGNORED(name),
CR_IGNORED(order),
CR_IGNORED(synced_),

CR_IGNORED(los),
CR_IGNORED(airLos),
CR_IGNORED(radar),
CR_IGNORED(sonar),
CR_IGNORED(seismic),
CR_IGNORED(commonJammer),
CR_IGNORED(commonSonarJammer),
CR_MEMBER(baseRadarErrorSize),
CR_MEMBER(baseRadarErrorMult),
CR_MEMBER(radarErrorSizes),
CR_IGNORED(losTypes)
))


Expand Down Expand Up @@ -178,7 +165,7 @@ void ILosType::MoveUnit(CUnit* unit)
};

// unchanged?
SLosInstance* uli = reinterpret_cast<SLosInstance*>(unit->los[type]);
SLosInstance* uli = unit->los[type];
if (IS_FITTING_INSTANCE(uli)) {
return;
}
Expand Down Expand Up @@ -213,9 +200,9 @@ void ILosType::MoveUnit(CUnit* unit)
void ILosType::RemoveUnit(CUnit* unit, bool delayed)
{
if (delayed) {
DelayedFreeInstance(reinterpret_cast<SLosInstance*>(unit->los[type]));
DelayedFreeInstance(unit->los[type]);
} else {
UnrefInstance(reinterpret_cast<SLosInstance*>(unit->los[type]));
UnrefInstance(unit->los[type]);
}
unit->los[type] = nullptr;
}
Expand Down
8 changes: 1 addition & 7 deletions rts/Sim/Misc/LosHandler.h
Expand Up @@ -36,8 +36,6 @@
*/
struct SLosInstance
{
CR_DECLARE_STRUCT(SLosInstance)

SLosInstance(int radius, int allyteam, int2 basePos, float baseHeight, int hashNum)
: allyteam(allyteam)
, radius(radius)
Expand Down Expand Up @@ -84,9 +82,6 @@ struct SLosInstance
*/
class ILosType
{
CR_DECLARE_STRUCT(ILosType)
CR_DECLARE_SUB(DelayedInstance)

public:
// the Interface
int2 PosToSquare(const float3 pos) const { return int2( Round(pos.x * invDiv), Round(pos.z * invDiv) ); }
Expand Down Expand Up @@ -154,7 +149,6 @@ class ILosType

private:
struct DelayedInstance {
CR_DECLARE_STRUCT(DelayedInstance)
SLosInstance* instance;
int timeoutTime;
};
Expand All @@ -174,7 +168,7 @@ class ILosType
* so hills obstruct view (see CLosAlgorithm). The second is circular: air LOS
* is not influenced by terrain.
*/
class CLosHandler : public boost::noncopyable, public CEventClient
class CLosHandler : public CEventClient
{
CR_DECLARE_STRUCT(CLosHandler)
CLosHandler();
Expand Down
15 changes: 0 additions & 15 deletions rts/Sim/Misc/LosMap.cpp
Expand Up @@ -14,20 +14,6 @@



CR_BIND(CLosMap, (int2(), false, nullptr))
CR_REG_METADATA(CLosMap, (
CR_MEMBER(size),
CR_MEMBER(map),
CR_MEMBER(sendReadmapEvents)//,
//CR_MEMBER(heightmap)
))







//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// CLosTables precalc helper
Expand Down Expand Up @@ -476,7 +462,6 @@ void CLosMap::CastLos(std::vector<int>* squares, float* maxAng, const int2 pos,
void CLosMap::UnsafeLosAdd(int2 pos, int radius, float losHeight, std::vector<int>& squares)
{
const size_t area = Square((2*radius)+1);

const LosTable& table = CLosTables::GetForLosSize(radius);
size_t neededSpace = squares.size() + 1;
for (const LosLine& line: table) {
Expand Down
2 changes: 0 additions & 2 deletions rts/Sim/Misc/LosMap.h
Expand Up @@ -16,8 +16,6 @@ struct SLosInstance;
/// map containing counts of how many units have Line Of Sight (LOS) to each square
class CLosMap
{
CR_DECLARE_STRUCT(CLosMap)

public:
CLosMap(int2 size_, bool sendReadmapEvents_, const float* heightmap_)
: size(size_)
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/Units/Unit.cpp
Expand Up @@ -2385,7 +2385,7 @@ CR_REG_METADATA(CUnit, (
CR_MEMBER(category),

CR_MEMBER(quads),
//CR_MEMBER(los),
CR_IGNORED(los),

CR_MEMBER(mapSquare),

Expand Down
4 changes: 3 additions & 1 deletion rts/Sim/Units/Unit.h
Expand Up @@ -29,6 +29,8 @@ struct LocalModelPiece;
struct UnitDef;
struct UnitTrackStruct;
struct UnitLoadParams;
struct SLosInstance;


namespace icon {
class CIconData;
Expand Down Expand Up @@ -273,7 +275,7 @@ class CUnit : public CSolidObject
CUnitScript* script;

/// which squares the unit can currently observe
std::vector<void*> los;
std::vector<SLosInstance*> los;

/// indicate the los/radar status the allyteam has on this unit
std::vector<unsigned short> losStatus;
Expand Down
29 changes: 10 additions & 19 deletions rts/System/EventClient.h
Expand Up @@ -74,38 +74,29 @@ class CEventClient
return (GetFullRead() || (GetReadAllyTeam() == allyTeam));
}

public:
friend class CEventHandler;
protected:
CEventClient(const std::string& name, int order, bool synced);
virtual ~CEventClient();

typedef void (*eventFuncPtr)();
protected:
const std::string name;
const int order;
const bool synced_;
bool autoLinkEvents;

protected:
friend class CEventHandler;
std::map<std::string, bool> autoLinkedEvents;

template <class T>
void RegisterLinkedEvents(T* foo) {
// old way needed gcc's pmf extension to cast member functions
//autoLinkedEvents[#eventname] = (reinterpret_cast<eventFuncPtr>(&T::eventname) != reinterpret_cast<eventFuncPtr>(&CEventClient::eventname));

// new way, works everywhere
#define SETUP_EVENT(eventname, props) \
autoLinkedEvents[#eventname] = (typeid(&T::eventname) != typeid(&CEventClient::eventname));

#include "Events.def"
#undef SETUP_EVENT
}

private:
const std::string name;
const int order;
const bool synced_;

protected:
bool autoLinkEvents;

protected:
CEventClient(const std::string& name, int order, bool synced);
virtual ~CEventClient();

public:
/**
* @name Synced_events
Expand Down

0 comments on commit 7dca29a

Please sign in to comment.