Skip to content

Commit

Permalink
Review changes refactor 'unsigned int' ==> 'int'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Hake committed Aug 26, 2021
1 parent bb67d92 commit f495f8e
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/rwe/GameNetworkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace rwe
auto firstRelevantCommandIndex = (endpoint.nextCommandToReceive - firstCommandNumber).value;

// if the packet is relevant (contains new information), process it
if (firstRelevantCommandIndex < static_cast<int>(message.command_set_size()))
if (firstRelevantCommandIndex < message.command_set_size())
{
endpoint.lastReceiveTime = receiveTime;

Expand Down
2 changes: 1 addition & 1 deletion src/rwe/RenderService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ namespace rwe
auto timeSinceSpawn = currentTime - projectile.createdAt;
auto fullLifetime = projectile.dieOnFrame.value() - projectile.createdAt;
auto percentComplete = static_cast<float>(timeSinceSpawn.value) / static_cast<float>(fullLifetime.value);
int frameIndex = static_cast<int>(percentComplete * spriteSeries->sprites.size());
auto frameIndex = static_cast<int>(percentComplete * spriteSeries->sprites.size());
assert(frameIndex < spriteSeries->sprites.size());
const auto& sprite = *spriteSeries->sprites[frameIndex];
auto modelMatrix = Matrix4f::translation(snappedPosition) * conversionMatrix * sprite.getTransform();
Expand Down
8 changes: 4 additions & 4 deletions src/rwe/cob/CobEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace rwe
{
}

int CobEnvironment::getStatic(int id)
int CobEnvironment::getStatic(uint32_t id)
{
return _statics.at(id);
}

void CobEnvironment::setStatic(int id, int value)
void CobEnvironment::setStatic(uint32_t id, int value)
{
_statics.at(id) = value;
}
Expand Down Expand Up @@ -43,7 +43,7 @@ namespace rwe
return thread;
}

const CobThread* CobEnvironment::createThread(int functionId, const std::vector<int>& params, int signalMask)
const CobThread* CobEnvironment::createThread(int functionId, const std::vector<int>& params, unsigned int signalMask)
{
const auto& functionInfo = _script->functions.at(functionId);
auto& thread = threads.emplace_back(std::make_unique<CobThread>(functionInfo.name, signalMask));
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace rwe
}
}

void CobEnvironment::sendSignal(int signal)
void CobEnvironment::sendSignal(uint32_t signal)
{
for (auto it = threads.begin(); it != threads.end();)
{
Expand Down
12 changes: 6 additions & 6 deletions src/rwe/cob/CobEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace rwe
*/
struct SignalStatus
{
int signal;
uint32_t signal;
};

struct PieceCommandStatus
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace rwe
};
using CommandType = std::variant<Move, Turn, Spin, StopSpin, Show, Hide, EnableShading, DisableShading>;

int piece;
uint32_t piece;
CommandType command;
};

Expand Down Expand Up @@ -273,17 +273,17 @@ namespace rwe
CobEnvironment& operator=(CobEnvironment&& other) = delete;

public:
int getStatic(int id);
int getStatic(uint32_t id);

void setStatic(int id, int value);
void setStatic(uint32_t id, int value);

const CobScript* script();

std::optional<CobThread> createNonScheduledThread(const std::string& functionName, const std::vector<int>& params);

CobThread createNonScheduledThread(int functionId, const std::vector<int>& params);

const CobThread* createThread(int functionId, const std::vector<int>& params, int signalMask);
const CobThread* createThread(int functionId, const std::vector<int>& params, uint32_t signalMask);

const CobThread* createThread(int functionId, const std::vector<int>& params);

Expand All @@ -298,7 +298,7 @@ namespace rwe
* If the signal is non-zero after being ANDed
* with the thread's signal mask, the thread is killed.
*/
void sendSignal(int signal);
void sendSignal(uint32_t signal);

/**
* Attempts to collect the return value from a thread.
Expand Down
10 changes: 5 additions & 5 deletions src/rwe/cob/CobExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,14 @@ namespace rwe
return CobAngularSpeed(pop());
}

int CobExecutionContext::popSignal()
uint32_t CobExecutionContext::popSignal()
{
return pop();
return static_cast<uint32_t>(pop());
}

int CobExecutionContext::popSignalMask()
uint32_t CobExecutionContext::popSignalMask()
{
return pop();
return static_cast<uint32_t>(pop());
}

CobValueId CobExecutionContext::popValueId()
Expand Down Expand Up @@ -750,7 +750,7 @@ namespace rwe
}
}

int CobExecutionContext::nextInstruction()
uint32_t CobExecutionContext::nextInstruction()
{
return env->script()->instructions.at(thread->callStack.top().instructionIndex++);
}
Expand Down
6 changes: 3 additions & 3 deletions src/rwe/cob/CobExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ namespace rwe
CobSpeed popSpeed();
CobAngle popAngle();
CobAngularSpeed popAngularSpeed();
int popSignal();
int popSignalMask();
uint32_t popSignal();
uint32_t popSignalMask();
CobValueId popValueId();
void push(int val);

int nextInstruction();
uint32_t nextInstruction();
CobAxis nextInstructionAsAxis();
};
}
2 changes: 1 addition & 1 deletion src/rwe/cob/CobThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace rwe
{
CobThread::CobThread(const std::string& name, int signalMask) : name(name), signalMask(signalMask)
CobThread::CobThread(const std::string& name, uint32_t signalMask) : name(name), signalMask(signalMask)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/rwe/cob/CobThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace rwe

std::stack<int> stack;

int signalMask{0};
uint32_t signalMask{0};

std::stack<CobFunction> callStack;

Expand All @@ -27,7 +27,7 @@ namespace rwe
std::vector<int> returnLocals;

public:
CobThread(const std::string& name, int signalMask);
CobThread(const std::string& name, uint32_t signalMask);

explicit CobThread(const std::string& name);
};
Expand Down
1 change: 1 addition & 0 deletions src/rwe/grid/DiscreteRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace rwe
DiscreteRect() = default;
DiscreteRect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height)
{
assert(width >= 0 && height >= 0);
}

bool operator==(const DiscreteRect& rhs) const
Expand Down
11 changes: 8 additions & 3 deletions src/rwe/grid/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace rwe
GridCoordinates() = default;
GridCoordinates(int x, int y) : x(x), y(y)
{
assert(x >= 0 && y >= 0);
}

bool operator==(const GridCoordinates& rhs) const
Expand Down Expand Up @@ -47,7 +48,10 @@ namespace rwe
GridRegion() = default;

GridRegion(int x, int y, int width, int height)
: x(x), y(y), width(width), height(height) {}
: x(x), y(y), width(width), height(height)
{
assert(x >= 0 && y >= 0 && width >= 0 && height >= 0);
}

template <typename Func>
void forEach(Func f) const
Expand Down Expand Up @@ -118,14 +122,15 @@ namespace rwe
Grid() : width(0), height(0) {}

Grid(int width, int height)
: width(width), height(height), data(width * height) {}
: width(width), height(height), data(width * height) { assert(width >= 0 && height >= 0); }

Grid(int width, int height, const T& initialValue)
: width(width), height(height), data(width * height, initialValue) {}
: width(width), height(height), data(width * height, initialValue) { assert(width >= 0 && height >= 0); }

Grid(int width, int height, std::vector<T>&& data)
: width(width), height(height), data(std::move(data))
{
assert(width >= 0 && height >= 0);
assert(this->data.size() == width * height);
}

Expand Down
4 changes: 2 additions & 2 deletions src/rwe/ui/UiFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ namespace rwe
auto defaultSprite = textureService->getDefaultSprite();

const auto& sprites = (*graphics)->sprites;
int spriteCount = static_cast<int>(sprites.size());
auto spriteCount = static_cast<int>(sprites.size());

auto stagesPresentCount = spriteCount > 2 ? spriteCount - 2 : 0;
int stagesToCopyCount = std::min<int>(stages, stagesPresentCount);//TODO (kwh) - do
auto stagesToCopyCount = std::min<int>(stages, stagesPresentCount);//TODO (kwh) - do

std::vector<std::shared_ptr<Sprite>> normalSprites;
for (int i = 0; i < stagesToCopyCount; ++i)
Expand Down
2 changes: 1 addition & 1 deletion src/rwe/ui/UiListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace rwe

void UiListBox::render(UiRenderService& context) const
{
int lines = std::min<int>(numberOfLines(), items.size());
auto lines = std::min<int>(numberOfLines(), items.size());

for (int i = 0; i < lines; ++i)
{
Expand Down

0 comments on commit f495f8e

Please sign in to comment.