Skip to content

Commit

Permalink
Level load/save/edit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMoroz committed Apr 11, 2019
1 parent cffb276 commit c66df77
Show file tree
Hide file tree
Showing 32 changed files with 39 additions and 30 deletions.
Binary file modified game_folder/levels/Around_The_Citadel.lvl
Binary file not shown.
Binary file modified game_folder/levels/Around_The_World.lvl
Binary file not shown.
Binary file modified game_folder/levels/Asteroid_Field.lvl
Binary file not shown.
Binary file modified game_folder/levels/Beware_Of_Bumps.lvl
Binary file not shown.
Binary file modified game_folder/levels/Build_Up_Speed.lvl
Binary file not shown.
Binary file modified game_folder/levels/Building_Bridges.lvl
Binary file not shown.
Binary file modified game_folder/levels/Bunny_Hops.lvl
Binary file not shown.
Binary file modified game_folder/levels/Don't_Get_Crushed.lvl
Binary file not shown.
Binary file modified game_folder/levels/Expressways.lvl
Binary file not shown.
Binary file modified game_folder/levels/Fatal_Fissures.lvl
Binary file not shown.
Binary file modified game_folder/levels/Hole_In_One.lvl
Binary file not shown.
Binary file modified game_folder/levels/Jump_The_Crater.lvl
Binary file not shown.
Binary file modified game_folder/levels/Lily_Pads.lvl
Binary file not shown.
Binary file modified game_folder/levels/Mind_The_Gap.lvl
Binary file not shown.
Binary file modified game_folder/levels/Mountain_Climbing.lvl
Binary file not shown.
Binary file modified game_folder/levels/Planet_Crusher.lvl
Binary file not shown.
Binary file modified game_folder/levels/Pylon_Palace.lvl
Binary file not shown.
Binary file modified game_folder/levels/Ride_The_Gecko.lvl
Binary file not shown.
Binary file modified game_folder/levels/The_Catwalk.lvl
Binary file not shown.
Binary file modified game_folder/levels/The_Crown_Jewels.lvl
Binary file not shown.
Binary file modified game_folder/levels/The_Hills_Are_Alive.lvl
Binary file not shown.
Binary file modified game_folder/levels/The_Sponge.lvl
Binary file not shown.
Binary file modified game_folder/levels/Too_Many_Trees.lvl
Binary file not shown.
Binary file modified game_folder/levels/Top_Of_The_Citadel.lvl
Binary file not shown.
Binary file added game_folder/levels/World_tree.lvl
Binary file not shown.
4 changes: 2 additions & 2 deletions game_folder/shaders/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
#define AMBIENT_OCCLUSION_COLOR_DELTA vec3(0.7)
#define AMBIENT_OCCLUSION_STRENGTH 0.008
#define ANTIALIASING_SAMPLES 1
#define BACKGROUND_COLOR vec3(0.6,0.8,1.0)
#define COL col_scene
#define DE de_scene
#define DIFFUSE_ENABLED 0
#define DIFFUSE_ENHANCED_ENABLED 1
#define FILTERING_ENABLE 0
#define FOCAL_DIST 1.73205080757
#define FOG_ENABLED 0
#define LIGHT_COLOR vec3(1.0,0.95,0.8)
#define MAX_DIST 30.0
#define MAX_MARCHES 512
#define MIN_DIST 1e-5
Expand Down Expand Up @@ -64,6 +62,8 @@ uniform float CAMERA_SIZE;
uniform int FRACTAL_ITER;
uniform bool REFL_REFR_ENABLED;
uniform int MARBLE_MODE;
uniform vec3 BACKGROUND_COLOR;
uniform vec3 LIGHT_COLOR;

float FOVperPixel;
float s1, c1, s2, c2;
Expand Down
15 changes: 8 additions & 7 deletions src/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ Level::Level(float s, float a1, float a2,
light_col = Eigen::Vector3f(1.0, 0.95, 0.8);

level_id = 0;
link_level = 0;
link_level = -1;
use_music = "level1.ogg";

ground_force = 0.008f;
Expand Down Expand Up @@ -633,13 +633,14 @@ sf::Music* All_Levels::GetLevelMusic(int ID)
return music_map[level_map[ID].use_music];
}

void All_Levels::ReloadLevel(int IDt)
void All_Levels::ReloadLevels()
{
vector<fs::path> files = GetFilesInFolder(lvl_folder, ".lvl");
Level cur_lvl;
int ID = level_id_map[IDt];
cur_lvl.LoadFromFile(files[ID]);
level_map[IDt] = cur_lvl;
level_map.clear();
level_id_map.clear();
level_names.clear();
level_descriptions.clear();
level_ids.clear();
LoadLevelsFromFolder(lvl_folder);
}

void All_Levels::LoadLevelFromFile(fs::path file)
Expand Down
3 changes: 2 additions & 1 deletion src/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class All_Levels
std::vector<int> getLevelIds();
sf::Music* GetLevelMusic(int ID);

void ReloadLevel(int ID);
void ReloadLevels();

void LoadLevelFromFile(fs::path file);
sf::Music* GetMusicByID(int ID);

Expand Down
18 changes: 10 additions & 8 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ int main(int argc, char *argv[]) {
mouse_pos = sf::Vector2i(0, 0);
mouse_prev_pos = sf::Vector2i(0, 0);

//temporary code
for (int i = 0; i < 24; i++)
//temporary level generation code
/*for (int i = 0; i < 24; i++)
{
all_levels[i].desc = "Official Level by Codeparade";
all_levels[i].SaveToFile(std::string(level_folder) + "/" + ConvertSpaces2_(all_levels[i].txt)+".lvl", i, (i<24)?(i+1):-1);
}
}*/

scene.levels.LoadLevelsFromFolder(level_folder);
scene.levels.LoadMusicFromFolder(music_folder);
Expand Down Expand Up @@ -524,8 +524,8 @@ int main(int argc, char *argv[]) {
menu_music.stop();
scene.SetExposure(1.0f);
overlays.TWBAR_ENABLED = true;
TwDefine("LevelEditor visible=true position='30 100'");
TwDefine("FractalEditor visible=true position='30 400'");
TwDefine("LevelEditor visible=true position='20 20'");
TwDefine("FractalEditor visible=true position='20 500'");
TwDefine("Settings iconified=true");
TwDefine("Statistics iconified=true");
scene.StartLevelEditor(-1);
Expand All @@ -540,8 +540,8 @@ int main(int argc, char *argv[]) {
menu_music.stop();
scene.SetExposure(1.0f);
overlays.TWBAR_ENABLED = true;
TwDefine("LevelEditor visible=true position='30 100'");
TwDefine("FractalEditor visible=true position='30 400'");
TwDefine("LevelEditor visible=true position='20 20'");
TwDefine("FractalEditor visible=true position='20 500'");
TwDefine("Settings iconified=true");
TwDefine("Statistics iconified=true");
scene.StartLevelEditor(selected);
Expand Down Expand Up @@ -698,10 +698,12 @@ int main(int argc, char *argv[]) {
//Apply forces to marble and camera
scene.UpdateMarble(force_lr, force_ud);


scene.free_camera_speed *= 1 + mouse_wheel * 0.05;
//Collect mouse input
if (overlays.TWBAR_ENABLED)
{

sf::Vector2i mouse_delta = sf::Vector2i(0, 0);
window.setMouseCursorVisible(true);
if (mouse_clicked)
Expand Down
18 changes: 9 additions & 9 deletions src/Overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,13 @@ void TW_CALL SaveLevel(void *data)
bool same_level = scene_ptr->original_level_name == copy->txt;
if (lvlid < 0 || !same_level)
lvlid = time(NULL);
copy->level_id = lvlid;
copy->SaveToFile(std::string(level_folder) + "/" + ConvertSpaces2_(copy->txt) + ".lvl", lvlid, copy->link_level);
if (scene_ptr->GetLevel() >= 0 && same_level)
scene_ptr->levels.ReloadLevels();
if (!(scene_ptr->GetLevel() >= 0 && same_level))
{
scene_ptr->levels.ReloadLevel(scene_ptr->GetLevel());
}
else
{
scene_ptr->levels.LoadLevelFromFile(std::filesystem::path(std::string(level_folder) + "/" + ConvertSpaces2_(copy->txt) + ".lvl"));
scene_ptr->WriteLVL(lvlid);
scene_ptr->original_level_name = copy->txt;
}
}

Expand Down Expand Up @@ -558,12 +556,12 @@ void Overlays::SetAntTweakBar(int Width, int Height, float &fps, Scene *scene, b
}

TwType Levels = TwDefineEnum("levels", level_enums, level_list.size()+1);
TwAddVarRW(level_editor, "Play level after finish", Levels, &copy->link_level, "");
TwAddVarRW(level_editor, "Play level after finish(TODO)", Levels, &copy->link_level, "");

TwAddVarRW(level_editor, "Sun direction", TW_TYPE_DIR3F, copy->light_dir.data(), "group='Level parameters'");
TwAddVarRW(level_editor, "Sun color", TW_TYPE_DIR3F, copy->light_col.data(), "group='Level parameters'");
TwAddVarRW(level_editor, "Background color", TW_TYPE_DIR3F, copy->background_col.data(), "group='Level parameters'");
TwAddVarRW(level_editor, "Gravity strenght", TW_TYPE_FLOAT, &copy->gravity, "group='Level parameters'");
TwAddVarRW(level_editor, "Gravity strenght", TW_TYPE_FLOAT, &copy->gravity, "min=0 max=0.5 step=0.0001 group='Level parameters'");
fractal_editor = TwNewBar("FractalEditor");

TwAddVarRW(fractal_editor, "PBR roughness", TW_TYPE_FLOAT, &copy->PBR_roughness, "min=0 max=1 step=0.001 ");
Expand Down Expand Up @@ -847,7 +845,7 @@ void Menu::RenderMenu(sf::RenderWindow & window)
bool is_active = active == i;

float ycor = (GetElementYPosition(i) + 15) * draw_scale;
const sf::FloatRect bounds((menu_x - 20)*draw_scale + w_size_x * 0.8f, ycor, 20 * draw_scale, 20 * draw_scale);
sf::FloatRect bounds;
switch (types[i])
{
case Button:
Expand All @@ -869,9 +867,11 @@ void Menu::RenderMenu(sf::RenderWindow & window)
window.draw(text);

edit_spr.setPosition((menu_x - 20)*draw_scale + w_size_x * 0.8f , ycor);

bounds = edit_spr.getGlobalBounds();
bounds.width = edit_tex.getSize().x*draw_scale;
bounds.height = edit_tex.getSize().y*draw_scale;

inside_edit = inside_edit || bounds.contains(mouse.x, mouse.y);
window.draw(edit_spr);
break;
Expand Down
10 changes: 7 additions & 3 deletions src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static const int frame_deorbit = 800;
static const int frame_countdown = frame_deorbit + 3*60;
static const float default_zoom = 15.0f;
static const int fractal_iters = 16;
static const float gravity = 0.005f;
static const float ground_ratio = 1.15f;
static const int mus_switches[num_level_music] = {9, 15, 21, 24};
static const int num_levels_midpoint = 15;
Expand Down Expand Up @@ -82,7 +81,8 @@ Scene::Scene(sf::Music* level_music) :
PBR_ROUGHNESS(0.4),
camera_size(0.035),
cur_ed_mode(DEFAULT),
level_editor(false)
level_editor(false),
gravity(0.005f)
{
ResetCheats();
frac_params.setOnes();
Expand Down Expand Up @@ -312,6 +312,7 @@ void Scene::Synchronize()

void Scene::UpdateCamera(float dx, float dy, float dz, bool speedup) {
//Camera update depends on current mode
gravity = level_copy.gravity;
const int iters = speedup ? 5 : 1;
if (cam_mode == INTRO) {
UpdateIntro(false);
Expand Down Expand Up @@ -737,6 +738,9 @@ void Scene::Write(sf::Shader& shader) const {
shader.setUniform("PBR_ROUGHNESS", PBR_ROUGHNESS);
}

shader.setUniform("BACKGROUND_COLOR", sf::Glsl::Vec3(level_copy.background_col[0], level_copy.background_col[1], level_copy.background_col[2]));
shader.setUniform("LIGHT_COLOR", sf::Glsl::Vec3(level_copy.light_col[0], level_copy.light_col[1], level_copy.light_col[2]));

shader.setUniform("iMarbleRad", level_copy.marble_rad);

shader.setUniform("iFlagScale", level_copy.planet ? -level_copy.marble_rad : level_copy.marble_rad);
Expand All @@ -751,7 +755,7 @@ void Scene::Write(sf::Shader& shader) const {


shader.setUniform("SHADOWS_ENABLED", Shadows_Enabled);
shader.setUniform("CAMERA_SIZE", camera_size);
shader.setUniform("CAMERA_SIZE", camera_size*level_copy.marble_rad/0.035f);
shader.setUniform("FRACTAL_ITER", Fractal_Iterations);
shader.setUniform("REFL_REFR_ENABLED", Refl_Refr_Enabled);
shader.setUniform("MARBLE_MODE", MarbleType);
Expand Down
1 change: 1 addition & 0 deletions src/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,5 @@ class Scene {
bool hyper_speed;
bool disable_motion;
bool zoom_to_scale;
float gravity;
};

0 comments on commit c66df77

Please sign in to comment.