mirror of https://github.com/stella-emu/stella.git
Added destructive resize to LinkedObjectPool/RewindManager.
Fixed minor warnings in DebuggerDialog.
This commit is contained in:
parent
6632b97307
commit
8034bae9de
|
@ -59,9 +59,8 @@ class LinkedObjectPool
|
||||||
/*
|
/*
|
||||||
Create a pool of size CAPACITY; the active list starts out empty.
|
Create a pool of size CAPACITY; the active list starts out empty.
|
||||||
*/
|
*/
|
||||||
LinkedObjectPool<T, CAPACITY>() : myCurrent(myList.end()) {
|
LinkedObjectPool<T, CAPACITY>() : myCurrent(myList.end()), myCapacity(0) {
|
||||||
for(uInt32 i = 0; i < CAPACITY; ++i)
|
resize(CAPACITY);
|
||||||
myPool.emplace_back(T());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,6 +198,22 @@ class LinkedObjectPool
|
||||||
myPool.splice(myPool.end(), myList, std::next(myCurrent, 1), myList.end());
|
myPool.splice(myPool.end(), myList, std::next(myCurrent, 1), myList.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Resize the pool to specified size, invalidating the list in the process
|
||||||
|
(ie, the list essentially becomes empty again).
|
||||||
|
*/
|
||||||
|
void resize(uInt32 capacity) {
|
||||||
|
if(myCapacity != capacity) // only resize when necessary
|
||||||
|
{
|
||||||
|
myList.clear(); myPool.clear();
|
||||||
|
myCurrent = myList.end();
|
||||||
|
myCapacity = capacity;
|
||||||
|
|
||||||
|
for(uInt32 i = 0; i < myCapacity; ++i)
|
||||||
|
myPool.emplace_back(T());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Erase entire contents of active list.
|
Erase entire contents of active list.
|
||||||
*/
|
*/
|
||||||
|
@ -207,18 +222,11 @@ class LinkedObjectPool
|
||||||
myCurrent = myList.end();
|
myCurrent = myList.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
uInt32 capacity() const { return myCapacity; }
|
||||||
/** Access the list with iterators, just as you would a normal C++ STL list */
|
|
||||||
iter begin() { return myList.begin(); }
|
|
||||||
iter end() { return myList.end(); }
|
|
||||||
const_iter begin() const { return myList.cbegin(); }
|
|
||||||
const_iter end() const { return myList.cend(); }
|
|
||||||
#endif
|
|
||||||
uInt32 capacity() const { return CAPACITY; }
|
|
||||||
|
|
||||||
uInt32 size() const { return uInt32(myList.size()); }
|
uInt32 size() const { return uInt32(myList.size()); }
|
||||||
bool empty() const { return size() == 0; }
|
bool empty() const { return size() == 0; }
|
||||||
bool full() const { return size() >= CAPACITY; }
|
bool full() const { return size() >= capacity(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<T> myList, myPool;
|
std::list<T> myList, myPool;
|
||||||
|
@ -226,6 +234,9 @@ class LinkedObjectPool
|
||||||
// Current position in the active list (end() indicates an invalid position)
|
// Current position in the active list (end() indicates an invalid position)
|
||||||
iter myCurrent;
|
iter myCurrent;
|
||||||
|
|
||||||
|
// Total capacity of the pool
|
||||||
|
uInt32 myCapacity;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Following constructors and assignment operators not supported
|
// Following constructors and assignment operators not supported
|
||||||
LinkedObjectPool(const LinkedObjectPool&) = delete;
|
LinkedObjectPool(const LinkedObjectPool&) = delete;
|
||||||
|
|
|
@ -46,7 +46,7 @@ class RewindManager
|
||||||
RewindManager(OSystem& system, StateManager& statemgr);
|
RewindManager(OSystem& system, StateManager& statemgr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int NUM_INTERVALS = 7;
|
static constexpr int NUM_INTERVALS = 7;
|
||||||
const uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = {
|
const uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = {
|
||||||
76 * 262,
|
76 * 262,
|
||||||
76 * 262 * 3,
|
76 * 262 * 3,
|
||||||
|
@ -71,7 +71,7 @@ class RewindManager
|
||||||
"10s"
|
"10s"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int NUM_HORIZONS = 8;
|
static constexpr int NUM_HORIZONS = 8;
|
||||||
const uInt64 HORIZON_CYCLES[NUM_HORIZONS] = {
|
const uInt64 HORIZON_CYCLES[NUM_HORIZONS] = {
|
||||||
76 * 262 * 60 * 3,
|
76 * 262 * 60 * 3,
|
||||||
76 * 262 * 60 * 10,
|
76 * 262 * 60 * 10,
|
||||||
|
@ -124,6 +124,7 @@ class RewindManager
|
||||||
|
|
||||||
bool atFirst() const { return myStateList.atFirst(); }
|
bool atFirst() const { return myStateList.atFirst(); }
|
||||||
bool atLast() const { return myStateList.atLast(); }
|
bool atLast() const { return myStateList.atLast(); }
|
||||||
|
void resize(uInt32 size) { myStateList.resize(size); }
|
||||||
void clear() { myStateList.clear(); }
|
void clear() { myStateList.clear(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -972,19 +972,13 @@ void DeveloperDialog::handleSize()
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Int32 i;
|
Int32 i;
|
||||||
|
|
||||||
// handle illegal values
|
|
||||||
if(interval == -1)
|
|
||||||
interval = 0;
|
|
||||||
if(horizon == -1)
|
|
||||||
horizon = 0;
|
|
||||||
|
|
||||||
myStateSizeLabelWidget->setValue(size);
|
myStateSizeLabelWidget->setValue(size);
|
||||||
// adapt horizon and interval
|
// adapt horizon and interval
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
for(i = horizon; i < NUM_HORIZONS; ++i)
|
for(i = horizon; i < NUM_HORIZONS; ++i)
|
||||||
{
|
{
|
||||||
if((uInt64)size * instance().state().rewindManager().INTERVAL_CYCLES[interval]
|
if(uInt64(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval]
|
||||||
<= instance().state().rewindManager().HORIZON_CYCLES[i])
|
<= instance().state().rewindManager().HORIZON_CYCLES[i])
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -1023,18 +1017,12 @@ void DeveloperDialog::handleInterval()
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Int32 i;
|
Int32 i;
|
||||||
|
|
||||||
// handle illegal values
|
|
||||||
if(interval == -1)
|
|
||||||
interval = 0;
|
|
||||||
if(horizon == -1)
|
|
||||||
horizon = 0;
|
|
||||||
|
|
||||||
// adapt horizon and size
|
// adapt horizon and size
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
for(i = horizon; i < NUM_HORIZONS; ++i)
|
for(i = horizon; i < NUM_HORIZONS; ++i)
|
||||||
{
|
{
|
||||||
if((uInt64)size * instance().state().rewindManager().INTERVAL_CYCLES[interval]
|
if(uInt64(size) * instance().state().rewindManager().INTERVAL_CYCLES[interval]
|
||||||
<= instance().state().rewindManager().HORIZON_CYCLES[i])
|
<= instance().state().rewindManager().HORIZON_CYCLES[i])
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -1061,12 +1049,6 @@ void DeveloperDialog::handleHorizon()
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Int32 i;
|
Int32 i;
|
||||||
|
|
||||||
// handle illegal values
|
|
||||||
if(interval == -1)
|
|
||||||
interval = 0;
|
|
||||||
if(horizon == -1)
|
|
||||||
horizon = 0;
|
|
||||||
|
|
||||||
// adapt interval and size
|
// adapt interval and size
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue