2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** dthinker.h
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DTHINKER_H__
|
|
|
|
#define __DTHINKER_H__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dobject.h"
|
|
|
|
#include "statnums.h"
|
|
|
|
|
|
|
|
class AActor;
|
|
|
|
class player_t;
|
|
|
|
struct pspdef_s;
|
|
|
|
struct FState;
|
2016-03-28 15:27:55 +00:00
|
|
|
class DThinker;
|
2016-09-18 11:26:34 +00:00
|
|
|
class FSerializer;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
class FThinkerIterator;
|
|
|
|
|
|
|
|
enum { MAX_STATNUM = 127 };
|
|
|
|
|
|
|
|
// Doubly linked ring list of thinkers
|
|
|
|
struct FThinkerList
|
|
|
|
{
|
|
|
|
FThinkerList() : Sentinel(0) {}
|
|
|
|
void AddTail(DThinker *thinker);
|
|
|
|
DThinker *GetHead() const;
|
|
|
|
DThinker *GetTail() const;
|
|
|
|
bool IsEmpty() const;
|
|
|
|
|
|
|
|
DThinker *Sentinel;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DThinker : public DObject
|
|
|
|
{
|
|
|
|
DECLARE_CLASS (DThinker, DObject)
|
|
|
|
public:
|
|
|
|
DThinker (int statnum = STAT_DEFAULT) throw();
|
2017-01-12 21:49:18 +00:00
|
|
|
void OnDestroy () override;
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual ~DThinker ();
|
|
|
|
virtual void Tick ();
|
2016-11-24 20:36:02 +00:00
|
|
|
void CallTick();
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual void PostBeginPlay (); // Called just before the first tick
|
2017-01-30 07:10:33 +00:00
|
|
|
virtual void CallPostBeginPlay(); // different in actor.
|
2016-09-19 08:34:54 +00:00
|
|
|
virtual void PostSerialize();
|
2016-03-01 15:47:10 +00:00
|
|
|
size_t PropagateMark();
|
|
|
|
|
|
|
|
void ChangeStatNum (int statnum);
|
|
|
|
|
|
|
|
static void RunThinkers ();
|
|
|
|
static void RunThinkers (int statnum);
|
|
|
|
static void DestroyAllThinkers ();
|
2016-08-26 00:16:06 +00:00
|
|
|
static void DestroyThinkersInList(int statnum)
|
|
|
|
{
|
2016-08-26 06:34:27 +00:00
|
|
|
DestroyThinkersInList(Thinkers[statnum]);
|
|
|
|
DestroyThinkersInList(FreshThinkers[statnum]);
|
2016-08-26 00:16:06 +00:00
|
|
|
}
|
2016-09-18 11:26:34 +00:00
|
|
|
static void SerializeThinkers(FSerializer &arc, bool keepPlayers);
|
2016-03-01 15:47:10 +00:00
|
|
|
static void MarkRoots();
|
|
|
|
|
|
|
|
static DThinker *FirstThinker (int statnum);
|
2016-09-22 22:45:41 +00:00
|
|
|
static bool bSerialOverride;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-04-14 11:31:58 +00:00
|
|
|
// only used internally but Create needs access.
|
2016-03-01 15:47:10 +00:00
|
|
|
enum no_link_type { NO_LINK };
|
|
|
|
DThinker(no_link_type) throw();
|
2017-04-14 11:31:58 +00:00
|
|
|
private:
|
2016-03-01 15:47:10 +00:00
|
|
|
static void DestroyThinkersInList (FThinkerList &list);
|
2018-10-31 19:07:24 +00:00
|
|
|
static bool DoDestroyThinkersInList(FThinkerList &list);
|
2016-03-01 15:47:10 +00:00
|
|
|
static int TickThinkers (FThinkerList *list, FThinkerList *dest); // Returns: # of thinkers ticked
|
2017-07-17 08:21:58 +00:00
|
|
|
static int ProfileThinkers(FThinkerList *list, FThinkerList *dest);
|
2016-09-18 11:26:34 +00:00
|
|
|
static void SaveList(FSerializer &arc, DThinker *node);
|
2016-03-01 15:47:10 +00:00
|
|
|
void Remove();
|
|
|
|
|
|
|
|
static FThinkerList Thinkers[MAX_STATNUM+2]; // Current thinkers
|
|
|
|
static FThinkerList FreshThinkers[MAX_STATNUM+1]; // Newly created thinkers
|
|
|
|
|
|
|
|
friend struct FThinkerList;
|
|
|
|
friend class FThinkerIterator;
|
|
|
|
friend class DObject;
|
- removed the sequential processing of JSON objects because the benefit is too small.
After testing with a savegame on ZDCMP2 which is probably the largest map in existence, timing both methods resulted in a speed difference of less than 40 ms (70 vs 110 ms for reading all sectory, linedefs, sidedefs and objects).
This compares to an overall restoration time, including reloading the level, precaching all textures and setting everything up, of approx. 1.2 s, meaning an increase of 3% of the entire reloading time.
That's simply not worth all the negative side effects that may happen with a method that highly depends on proper code construction.
On the other hand, using random access means that a savegame version change is only needed now when the semantics of a field change, but not if some get added or deleted.
- do not I_Error out in the serializer unless caused by a programming error.
It is better to let the serializer finish, collect all the errors and I_Error out when the game is known to be in a stable enough state to allow unwinding.
2016-09-23 12:04:05 +00:00
|
|
|
friend class FSerializer;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DThinker *NextThinker, *PrevThinker;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FThinkerIterator
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const PClass *m_ParentType;
|
|
|
|
private:
|
|
|
|
DThinker *m_CurrThinker;
|
2017-03-08 17:47:52 +00:00
|
|
|
uint8_t m_Stat;
|
2016-03-01 15:47:10 +00:00
|
|
|
bool m_SearchStats;
|
|
|
|
bool m_SearchingFresh;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FThinkerIterator (const PClass *type, int statnum=MAX_STATNUM+1);
|
|
|
|
FThinkerIterator (const PClass *type, int statnum, DThinker *prev);
|
2016-11-05 00:19:41 +00:00
|
|
|
DThinker *Next (bool exact = false);
|
2016-03-01 15:47:10 +00:00
|
|
|
void Reinit ();
|
2017-01-29 17:23:09 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FThinkerIterator() {}
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> class TThinkerIterator : public FThinkerIterator
|
|
|
|
{
|
|
|
|
public:
|
2017-04-14 14:54:01 +00:00
|
|
|
TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_CLASS(T), statnum)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
}
|
2017-04-14 14:54:01 +00:00
|
|
|
TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_CLASS(T), statnum, prev)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
TThinkerIterator (FName subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
TThinkerIterator (ENamedName subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
TThinkerIterator (const char *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum)
|
|
|
|
{
|
|
|
|
}
|
2016-11-05 00:19:41 +00:00
|
|
|
T *Next (bool exact = false)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-11-05 00:19:41 +00:00
|
|
|
return static_cast<T *>(FThinkerIterator::Next (exact));
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__DTHINKER_H__
|