Skip to content

Commit

Permalink
Got redis-plus-plus working
Browse files Browse the repository at this point in the history
  • Loading branch information
vickylance committed Oct 7, 2023
1 parent 938a808 commit 561ff30
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 48 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ include(godot-dev-configuration)

find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(hiredis CONFIG REQUIRED)
find_package(redis++ CONFIG REQUIRED)

# =======================================================================
Expand Down Expand Up @@ -175,8 +173,6 @@ target_link_libraries(${PROJECT_NAME}
PRIVATE fmt::fmt
PRIVATE fmt::fmt-header-only
PRIVATE spdlog::spdlog_header_only
PRIVATE OpenSSL::SSL OpenSSL::Crypto
PRIVATE hiredis::hiredis
PRIVATE PRIVATE redis++::redis++_static
)

Expand Down
6 changes: 3 additions & 3 deletions src/entity/character/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace rl
if (m_character_controller != nullptr)
{
signal<event::character_move>::connect<CharacterController>(m_character_controller)
<=> slot(this, on_character_movement);
<=> g_slot(this, on_character_movement);

signal<event::character_rotate>::connect<CharacterController>(m_character_controller)
<=> slot(this, on_character_rotate);
<=> g_slot(this, on_character_rotate);

signal<event::character_shoot>::connect<CharacterController>(m_character_controller)
<=> slot(this, on_character_shoot);
<=> g_slot(this, on_character_shoot);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/entity/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ namespace rl
if (controller != nullptr)
{
signal<event::position_changed>::connect<CharacterController>(controller)
<=> slot(this, on_character_position_changed);
<=> g_slot(this, on_character_position_changed);

signal<event::spawn_projectile>::connect<Player>(m_player)
<=> slot(this, on_player_spawn_projectile);
<=> g_slot(this, on_player_spawn_projectile);
}
}

Expand Down Expand Up @@ -100,10 +100,10 @@ namespace rl
projectile->set_rotation(firing_pt->get_global_rotation());

signal<event::body_entered>::connect<Projectile>(projectile)
<=> slot(this, on_physics_box_entered);
<=> g_slot(this, on_physics_box_entered);

signal<event::body_exited>::connect<Projectile>(projectile)
<=> slot(this, on_physics_box_exited);
<=> g_slot(this, on_physics_box_exited);
}

this->add_child(projectile);
Expand Down
45 changes: 10 additions & 35 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "util/engine.hpp"
#include "util/input.hpp"

#include <hiredis/hiredis.h>
#include <sw/redis++/redis++.h>

#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/input.hpp>
Expand All @@ -14,49 +14,24 @@
#include <godot_cpp/variant/utility_functions.hpp>

using namespace godot;
using namespace sw::redis;

namespace rl
{
Main::Main()
{
redisContext* context = redisConnect("localhost", 6379);
if (context == NULL || context->err)
try
{
if (context)
{
UtilityFunctions::print("Connection error: %s\n", context->errstr);
redisFree(context);
}
else
{
UtilityFunctions::print("Connection error: Can't allocate redis context\n");
}
exit(1);
auto redis = Redis("tcp://127.0.0.1:6379");
// redis.set("key", "val");
auto val = redis.get("key");
std::string std_val = *val;
UtilityFunctions::print("VALUE: ", std_val.c_str());
}

UtilityFunctions::print("Redis connection successful");

// SET a key-value pair
redisReply* reply = (redisReply*)redisCommand(context, "SET mykey myvalue");
if (reply == NULL)
{
UtilityFunctions::print("SET failed\n");
exit(1);
}
freeReplyObject(reply);
UtilityFunctions::print("Redis SET successful");

// GET the value of a key
redisReply* getReply = (redisReply*)redisCommand(context, "GET mykey");
if (getReply == NULL)
catch (const sw::redis::Error& e)
{
UtilityFunctions::print("GET failed\n");
exit(1);
// Error handling.
}
UtilityFunctions::print("GET mykey: ", getReply->str);
freeReplyObject(getReply);

redisFree(context);

resource::preload::scene<Level> level{ path::scene::Level1 };
resource::preload::scene<MainDialog> dialog{ path::ui::MainDialog };
Expand Down
2 changes: 1 addition & 1 deletion src/util/bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define bind_member_function(class_name, func_name) method<&class_name::func_name>::bind(#func_name)

#define slot(slot_owner, slot_callback) \
#define g_slot(slot_owner, slot_callback) \
std::forward_as_tuple(godot::Callable(slot_owner, #slot_callback), slot_owner)

#define bind_property(class_name, prop_name, prop_type) \
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"documentation": "https://github.com/microsoft/vcpkg/blob/master/docs/users/manifests.md",
"name": "roguelite",
"version": "0.1.0",
"dependencies": ["fmt", "spdlog", "openssl", "hiredis", "redis-plus-plus"]
"dependencies": ["fmt", "spdlog", "redis-plus-plus"]
}

0 comments on commit 561ff30

Please sign in to comment.