Skip to content

Commit

Permalink
create Option system for distributing changes
Browse files Browse the repository at this point in the history
All old usages removed
  • Loading branch information
enginmanap committed Nov 23, 2024
1 parent 3c1a55e commit 2ee6937
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/GameObjects/Players/FreeCursorPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ void FreeCursorPlayer::rotate(float xPosition, float yPosition, float xChange [[
// FIXME this look around code is repeated in each player. I believe it should have been part of player class.
// It can't be used directly because that would eliminate possibilities like 3rd person cameras.

float lookAroundSpeed;
options->getOption("lookAroundSpeed", lookAroundSpeed);
float lookAroundSpeed = lookAroundSpeedOption.get();

//scale look around speed with the abs(center.y). for 1 -> look around 0, for 0 -> lookaround 1.
lookAroundSpeed = lookAroundSpeed * (1- (center.y * center.y));
Expand Down
3 changes: 1 addition & 2 deletions src/GameObjects/Players/FreeMovingPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void FreeMovingPlayer::move(moveDirections direction) {
void FreeMovingPlayer::rotate(float xPosition [[gnu::unused]], float yPosition [[gnu::unused]], float xChange, float yChange) {
dirty = true;
glm::quat viewChange;
float lookAroundSpeed;
options->getOption("lookAroundSpeed", lookAroundSpeed);
float lookAroundSpeed = lookAroundSpeedOption.get();
float lookAroundSpeedX = lookAroundSpeed;
//scale look around speed with the abs(center.y). for 1 -> look around 0, for 0 -> lookaround 1.
float lookAroundSpeedY = lookAroundSpeedX * (1- (center.y * center.y));
Expand Down
3 changes: 1 addition & 2 deletions src/GameObjects/Players/PhysicalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ void PhysicalPlayer::rotate(float xPosition __attribute__((unused)), float yPo
dirty = true;
glm::quat viewChange;

float lookAroundSpeedX;
options->getOption("lookAroundSpeed", lookAroundSpeedX);
float lookAroundSpeedX = lookAroundSpeedOption.get();
//scale look around speed with the abs(center.y). for 1 -> look around 0, for 0 -> lookaround 1.
float lookAroundSpeedY = lookAroundSpeedX;
if(((center.y > 0 && yChange < 0) || (center.y < 0 && yChange > 0))) { //if player is moving mouse on the direction. Looking up, moving mouse up, or vice versa. yChange is in reverse
Expand Down
5 changes: 4 additions & 1 deletion src/GameObjects/Players/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class Player : public GameObject {
PlayerExtensionInterface* playerExtension = nullptr;

OptionsUtil::Options::Option<LimonTypes::Vec4> moveSpeedOption;
OptionsUtil::Options::Option<double> jumpFactorOption;
OptionsUtil::Options::Option<LimonTypes::Vec4> walkSpeedOption;
OptionsUtil::Options::Option<LimonTypes::Vec4> runSpeedOption;
OptionsUtil::Options::Option<double> jumpFactorOption;
OptionsUtil::Options::Option<double> lookAroundSpeedOption;

bool dead = false;
public:
enum moveDirections {
Expand All @@ -54,6 +56,7 @@ class Player : public GameObject {
jumpFactorOption = options->getOption<double>(HASH("jumpFactor"));
walkSpeedOption = options->getOption<LimonTypes::Vec4>(HASH("walkSpeed"));
runSpeedOption = options->getOption<LimonTypes::Vec4>(HASH("runSpeed"));
lookAroundSpeedOption = options->getOption<double>(HASH("lookAroundSpeed"));
};

virtual ~Player() {}
Expand Down
1 change: 0 additions & 1 deletion src/Graphics/RenderMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class RenderMethods {
OptionsUtil::Options *options) const {

OptionsUtil::Options::Option<long> optionNewSet = options->getOption<long>(HASH("CascadeCount"));
OptionsUtil::Options::Option<double> option2 = options->getOption<double>(HASH("lookAroundSpeed"));
return RenderMethod("All directional shadows",
1,
nullptr,
Expand Down
21 changes: 0 additions & 21 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,6 @@ namespace OptionsUtil {
return Option<LimonTypes::Mat4>(nullptr, false);
}

bool getOption(const std::string &optionName, std::vector<long> &value) const {
auto it = this->options.find(getHash(optionName));
if (it == this->options.end() || it->second->valueType != LimonTypes::GenericParameter::LONG_ARRAY) {
return false;
}
value.clear();
for (long i = 1; i < it->second->value.longValues[0]; ++i) {
value.push_back(it->second->value.longValues[i]);
}
return true;
}

bool getOption(const std::string &optionName, float &value) const {
auto it = this->options.find(getHash(optionName));
if (it == this->options.end() || it->second->valueType != LimonTypes::GenericParameter::DOUBLE) {
return false;
}
value = (float) it->second->value.doubleValue;
return true;
}

/**
* This method is a workaround for API usage, it will find the hash of the string by
* iterating over all the options. If no option with that name exists, it will return 0.
Expand Down
13 changes: 12 additions & 1 deletion src/VisibilityRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ class VisibilityRequest {
const Camera* const camera;
glm::vec3 playerPosition;
const OptionsUtil::Options* options;
const OptionsUtil::Options::Option<std::vector<long>> lodDistancesOption;
const OptionsUtil::Options::Option<double> skipRenderDistanceOption;
const OptionsUtil::Options::Option<double> skipRenderSizeOption;
const OptionsUtil::Options::Option<double> maxSkipRenderSizeOption;
const std::unordered_map<uint32_t, PhysicalRenderable *>* const objects;
std::unordered_map<std::vector<uint64_t>, std::unordered_map<uint32_t , std::pair<std::vector<uint32_t>, uint32_t>>, uint64_vector_hasher> * visibility;
bool running = true;
std::atomic<uint32_t> frameCount;
SDL2MultiThreading::SpinLock inProgressLock;
SDL_mutex* blockMutex = SDL_CreateMutex();
VisibilityRequest(Camera* camera, std::unordered_map<uint32_t, PhysicalRenderable *>* objects, std::unordered_map<std::vector<uint64_t>, std::unordered_map<uint32_t , std::pair<std::vector<uint32_t>, uint32_t>>, uint64_vector_hasher> * visibility, const glm::vec3& playerPosition, const OptionsUtil::Options* options) :
camera(camera), playerPosition(playerPosition), options(options), objects(objects), visibility(visibility), frameCount(0) {};
camera(camera), playerPosition(playerPosition), options(options),
lodDistancesOption(options->getOption<std::vector<long>>(HASH("LodDistanceList"))),
skipRenderDistanceOption(options->getOption<double>(HASH("SkipRenderDistance"))),
skipRenderSizeOption(options->getOption<double>(HASH("SkipRenderSize"))),
maxSkipRenderSizeOption(options->getOption<double>(HASH("MaxSkipRenderSize"))),
objects(objects), visibility(visibility), frameCount(0) {

};

std::unordered_map<std::vector<uint64_t>, std::unordered_map<uint32_t , std::pair<std::vector<uint32_t>, uint32_t>>>::iterator findHashEntry(uint64_t hash) const {
std::unordered_map<std::vector<uint64_t>, std::unordered_map<uint32_t , std::pair<std::vector<uint32_t>, uint32_t>>>::iterator it = visibility->begin();
Expand Down
9 changes: 4 additions & 5 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,14 @@ void World::resetCameraTagsFromPipeline(const std::map<std::string, std::vector<

void* fillVisibleObjectPerCamera(const void* visibilityRequestRaw) {
const VisibilityRequest* visibilityRequest = static_cast<const VisibilityRequest *>(visibilityRequestRaw);
std::vector<long> lodDistances;
std::vector<long> lodDistances = visibilityRequest->lodDistancesOption.get();
float skipRenderDistance = 0, skipRenderSize = 0, maxSkipRenderSize = 0;
visibilityRequest->options->getOption("LodDistanceList", lodDistances);
glm::mat4 viewMatrix;
if(visibilityRequest->camera->getType() == Camera::CameraTypes::PERSPECTIVE ||
visibilityRequest->camera->getType() == Camera::CameraTypes::ORTHOGRAPHIC) {
visibilityRequest->options->getOption("SkipRenderDistance", skipRenderDistance);
visibilityRequest->options->getOption("SkipRenderSize", skipRenderSize);
visibilityRequest->options->getOption("MaxSkipRenderSize", maxSkipRenderSize);
skipRenderDistance = visibilityRequest->skipRenderDistanceOption.get();
skipRenderSize = visibilityRequest->skipRenderSizeOption.get();
maxSkipRenderSize = visibilityRequest->maxSkipRenderSizeOption.get();
viewMatrix = visibilityRequest->camera->getProjectionMatrix() * visibilityRequest->camera->getCameraMatrixConst();
}
for (auto objectIt = visibilityRequest->objects->begin(); objectIt != visibilityRequest->objects->end(); ++objectIt) {
Expand Down

0 comments on commit 2ee6937

Please sign in to comment.