Skip to content

Fix/cutscene lights #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"game": {
"maze": {
"directory": "maps",
"procedural": true,
"maze_file": "test/orb_drop.maze"
"procedural": false,
"maze_file": "test/itemRoom.maze"
},
"disable_enemies": true
},
Expand All @@ -21,10 +21,10 @@
"client": {
"default_name": "Conan O'Brien",
"lobby_discovery": true,
"fullscreen": true,
"fullscreen": false,
"draw_bboxes": false,
"fps_counter": true,
"presentation": false,
"render": 75
"render": 50
}
}
1 change: 1 addition & 0 deletions include/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class Client {
std::unique_ptr<Model> lava_cross_model;
std::unique_ptr<Model> lava_vertical_model;
std::unique_ptr<Model> lava_horizontal_model;
std::unique_ptr<Model> lightning_model;

GLFWwindow *window;

Expand Down
3 changes: 3 additions & 0 deletions include/server/game/exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Exit : public Object {
void doCollision(Object* other, ServerGameState& state) override;

virtual SharedObject toShared() override;

void setIntensity(float val);
private:
float intensity;
PointLightProperties properties;
};
11 changes: 11 additions & 0 deletions include/server/game/introcutscene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ class IntroCutscene {

LoadIntroCutsceneEvent toNetwork();

inline static const int START_TICK = 1;
inline static const int STOP_MOVING_TICK = START_TICK + 250;
inline static const int GATE_RAISE_TICK = STOP_MOVING_TICK + 30;
inline static const int GATE_STOP_RAISE_TICK = GATE_RAISE_TICK + 200;
inline static const int LIGHTNING_1_TICK = GATE_STOP_RAISE_TICK + 80;
inline static const int LIGHTNING_2_TICK = LIGHTNING_1_TICK + 50;
inline static const int LIGHTNING_3_TICK = LIGHTNING_2_TICK + 40;
inline static const int START_PLAYER_THEME_TICK = LIGHTNING_3_TICK + 110;
inline static const int EXIT_CUTSCENE_TICK = START_PLAYER_THEME_TICK + 240;

int ticks;

// just making everything public bc lazy
ServerGameState state;
Expand Down
8 changes: 8 additions & 0 deletions include/server/game/torchlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ class Torchlight : public Object {
*/
void doTick(ServerGameState& state, std::optional<glm::vec3> lightning_light_cut_pos, std::optional<glm::vec3> action_light_cut_pos);

/**
* @brief manually set torchlight intensity, for use in intro cutscene
*/
void overrideIntensity(float val);

/**
* @brief get current intensity of torch from 0-1
*/
float getIntensity() const;

bool is_cut;
private:
PointLightProperties properties;


// current intensity from 0-1 that gets
// sent to client
float curr_intensity;
Expand Down
4 changes: 2 additions & 2 deletions include/server/game/weaponcollider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WeaponCollider : public Object {
bool timeOut(ServerGameState& state);
virtual SharedObject toShared() override;

private:
protected:
std::chrono::time_point<std::chrono::system_clock> preparing_time;
std::chrono::time_point<std::chrono::system_clock> attacked_time;
Player* usedPlayer;
Expand Down Expand Up @@ -92,7 +92,7 @@ class Lightning : public WeaponCollider {
virtual SharedObject toShared() override {
auto so = WeaponCollider::toShared();
so.pointLightInfo = SharedPointLightInfo {
.intensity = 1.0f,
.intensity = (this->info.attacked) ? 1.0f : 0.3f,
.ambient_color = this->properties.ambient_color,
.diffuse_color = this->properties.diffuse_color,
.specular_color = this->properties.specular_color,
Expand Down
3 changes: 2 additions & 1 deletion include/shared/game/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ struct UpdateLightSourcesEvent {
struct UpdatedLightSource {
EntityID eid;
float intensity;
bool is_cut;
DEF_SERIALIZE(Archive& ar, const unsigned int version) {
ar & eid & intensity;
ar & eid & intensity & is_cut;
}
};
std::array<boost::optional<UpdatedLightSource>, MAX_POINT_LIGHTS> lightSources;
Expand Down
4 changes: 3 additions & 1 deletion include/shared/game/sharedobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ struct SharedPointLightInfo {
float attenuation_linear;
float attenuation_quadratic;

bool is_cut = false;

DEF_SERIALIZE(Archive& ar, const int version) {
ar & intensity & ambient_color & diffuse_color & specular_color &
attenuation_linear & attenuation_quadratic;
attenuation_linear & attenuation_quadratic & is_cut;
}
};

Expand Down
4 changes: 2 additions & 2 deletions maps/cutscene/intro.maze
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##########[#####[#####[####
################[##########
.........................!o
..........@..............!o
.........................!o
.........................!o
##########]#####]#####]####
################]##########
42 changes: 32 additions & 10 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ bool Client::init() {
auto exit_model_path = env_models_dir / "exit.obj";
this->exit_model = std::make_unique<Model>(exit_model_path.string(), true);

auto lightning_model_path = env_models_dir / "Lightning1" / "Lightning1_translated.obj";
this->lightning_model = std::make_unique<Model>(lightning_model_path.string(), true);

auto player_walk_path = graphics_assets_dir / "animations/walk.fbx";
auto player_jump_path = graphics_assets_dir / "animations/jump.fbx";
auto player_idle_path = graphics_assets_dir / "animations/idle.fbx";
Expand Down Expand Up @@ -687,6 +690,8 @@ void Client::processServerInput(bool allow_defer) {
this->closest_light_sources[i] = this->gameState.objects[light_id];
// update intensity with incoming intensity
this->closest_light_sources[i]->pointLightInfo->intensity = updated_light_source.lightSources[i]->intensity;
this->closest_light_sources[i]->pointLightInfo->is_cut = updated_light_source.lightSources[i]->is_cut;
this->gameState.objects.at(light_id)->pointLightInfo->is_cut = updated_light_source.lightSources[i]->is_cut;
}
} else if (event.type == EventType::LoadIntroCutscene) {
const auto& data = boost::get<LoadIntroCutsceneEvent>(event.data);
Expand Down Expand Up @@ -1228,19 +1233,21 @@ void Client::geometryPass() {
case ObjectType::WeaponCollider: {
if (sharedObject->weaponInfo->lightning) {
if (!sharedObject->weaponInfo->attacked) {
glm::vec3 preview_dims = sharedObject->physics.dimensions;
preview_dims.y = 0.01f;
this->item_model->setDimensions(preview_dims);
this->exit_model->setDimensions(glm::vec3(3.0f, 0.01f, 3.0f));
glm::vec3 preview_pos = sharedObject->physics.getCenterPosition();
preview_pos.y = 0.0f;
this->item_model->translateAbsolute(preview_pos);
this->item_model->draw(this->deferred_geometry_shader.get(),
this->exit_model->translateAbsolute(preview_pos);
this->exit_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
} else {
this->item_model->setDimensions(sharedObject->physics.dimensions);
this->item_model->translateAbsolute(sharedObject->physics.getCenterPosition());
this->item_model->draw(this->deferred_geometry_shader.get(),
this->lightning_model->setDimensions(glm::vec3(1.314906, 2.238910 * 2.0f, 0.019732) * 10.0f);
this->lightning_model->translateAbsolute(sharedObject->physics.corner);
glm::vec3 facing_curr_player = rotate90DegreesAroundYAxis(glm::normalize(
sharedObject->physics.getCenterPosition() - cam->getPos()
));
this->lightning_model->rotateAbsolute(facing_curr_player);
this->lightning_model->draw(this->deferred_geometry_shader.get(),
this->cam->getPos(),
true);
}
Expand Down Expand Up @@ -1336,6 +1343,10 @@ void Client::lightingPass() {
for (int i = 0; i < closest_lights->size(); i++) {
boost::optional<SharedObject>& curr_source = closest_lights->at(i);
if (!curr_source.has_value()) {
// put the light in africa so it isn't shown
// important for intro cutscene since other lights wont replace entries that are removed!
glm::vec3 FAR_AWAY(10000, 10000, 10000);
lighting_shader->setVec3("pointLights[" + std::to_string(i) + "].position", FAR_AWAY);
continue;
}

Expand Down Expand Up @@ -1427,14 +1438,25 @@ void Client::lightingPass() {
Model* torch_frame_model = animManager->updateFrameAnimation(glfwGetTime());
glm::vec3 dims = torch_frame_model->getDimensions();
this->deferred_light_box_shader->use();
this->deferred_light_box_shader->setVec3("lightColor", properties.diffuse_color);

glm::vec3 flame_color;

if (sharedObject->pointLightInfo->is_cut) {
glm::vec3 black(0.1f, 0.1f, 0.1f);
flame_color = black;
} else {
flame_color = properties.diffuse_color;
}

this->deferred_light_box_shader->setVec3("lightColor", flame_color);

// this->torchlight_model->setDimensions(2.0f * sharedObject->physics.dimensions);
// this->torchlight_model->translateAbsolute(sharedObject->physics.getCenterPosition());
// this->torchlight_model->draw(this->deferred_light_box_shader.get(), this->cam->getPos(), true);
torch_frame_model->setDimensions(2.0f * sharedObject->physics.dimensions);
torch_frame_model->translateAbsolute(sharedObject->physics.getCenterPosition());
// torch_frame_model->draw(this->deferred_light_box_shader.get(), this->cam->getPos(), true);
torch_frame_model->draw(this->deferred_light_box_shader.get(), this->cam->getPos(), true, properties.diffuse_color);
torch_frame_model->draw(this->deferred_light_box_shader.get(), this->cam->getPos(), true, flame_color);
}

}
Expand Down
9 changes: 7 additions & 2 deletions src/server/game/exit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Exit::Exit(bool open, glm::vec3 corner, glm::vec3 dimensions, const PointLightPr
properties(properties)
{
this->shared.open = open;
this->intensity = 1.0f;
}

void Exit::setIntensity(float val) {
this->intensity = val;
}

void Exit::doCollision(Object* other, ServerGameState& state) {
Expand Down Expand Up @@ -36,12 +41,12 @@ SharedObject Exit::toShared() {
auto so = Object::toShared();
so.exit = this->shared;
so.pointLightInfo = SharedPointLightInfo {
.intensity = 1.0f,
.intensity = this->intensity,
.ambient_color = this->properties.ambient_color,
.diffuse_color = this->properties.diffuse_color,
.specular_color = this->properties.specular_color,
.attenuation_linear = this->properties.attenuation_linear,
.attenuation_quadratic = this->properties.attenuation_quadratic,
.attenuation_quadratic = this->properties.attenuation_quadratic
};
return so;
}
Loading
Loading