1 /* This file is part of the Marble Marcher (https://github.com/HackerPoet/MarbleMarcher). 2 * Copyright(C) 2018 CodeParade 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program.If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #pragma once 18 19 #include "Level.h" 20 #include <SFML/Audio.hpp> 21 #include <SFML/Graphics.hpp> 22 #include <Eigen/Dense> 23 #include<Settings.h> 24 25 #define MAX_DIST 20.f 26 #define MAX_MARCHES 1000 27 #define MIN_DIST 1e-4f 28 #define FOCAL_DIST 1.73205080757 29 30 extern sf::Music *current_music; 31 extern bool recording; 32 extern bool replay; 33 34 struct InputRecord 35 { 36 float move_x, move_y; 37 float view_x, view_y; 38 float cam_z; 39 bool mouse_clicked; 40 }; 41 42 43 class Scene { 44 public: 45 enum CamMode { 46 INTRO, 47 SCREEN_SAVER, 48 ORBIT, 49 DEORBIT, 50 MARBLE, 51 GOAL, 52 FINAL, 53 MIDPOINT 54 }; 55 56 enum EditorMode 57 { 58 DEFAULT, 59 PLACE_MARBLE, 60 PLACE_FLAG 61 }; 62 63 EditorMode cur_ed_mode; 64 FractalParams frac_params; 65 FractalParams frac_params_smooth; 66 67 Level level_copy; 68 All_Levels levels; 69 70 bool PlayNext; 71 bool PBR_Enabled; 72 bool Refl_Refr_Enabled; 73 bool Shadows_Enabled; 74 bool Fog_Enabled; 75 int Fractal_Iterations; 76 float camera_size; 77 float free_camera_speed; 78 int MarbleType; 79 Eigen::Vector3f LIGHT_DIRECTION; 80 float PBR_METALLIC; 81 float PBR_ROUGHNESS; 82 83 float gamma_material; 84 float gamma_sky; 85 float gamma_camera; 86 87 std::string original_level_name; 88 89 float marble_rad; 90 Eigen::Vector3f marble_pos; 91 Eigen::Vector3f marble_vel; 92 Eigen::Matrix3f marble_mat; 93 94 void SetCurrentMusic(sf::Music * new_music); 95 96 void StopMusic(); 97 98 Scene(sf::Music* level_music); 99 100 void LoadLevel(int level); 101 void SetMarble(float x, float y, float z, float r); 102 void SetMarbleScale(float r); 103 void SetFlag(float x, float y, float z); 104 void SetMode(CamMode mode); 105 void SetResolution(int x, int y); SetExposure(float e)106 void SetExposure(float e) { exposure = e; } 107 void SetWindowResolution(int x, int y); EnbaleCheats()108 void EnbaleCheats() { enable_cheats = true; } 109 Eigen::Vector3f GetVelocity(); 110 GetMarble()111 const Eigen::Vector3f& GetMarble() const { return marble_pos; }; GetCamLook()112 float GetCamLook() const { return cam_look_x_smooth; } GetCamLookX()113 float GetCamLookX() const { return cam_look_x; } GetMarbleScale()114 float GetMarbleScale() const { return marble_rad; } GetFlagPos()115 const Eigen::Vector3f& GetFlagPos() const { return flag_pos; } GetMode()116 CamMode GetMode() const { return cam_mode; } GetLevel()117 int GetLevel() const { return cur_level; } 118 int GetCountdownTime() const; GetSumTime()119 int GetSumTime() const { return sum_time; } 120 sf::Vector3f GetGoalDirection() const; IsSinglePlay()121 bool IsSinglePlay() const { return play_single; } 122 bool IsHighScore(); IsFullRun()123 bool IsFullRun() const { return is_fullrun && !enable_cheats; } IsFreeCamera()124 bool IsFreeCamera() const { return free_camera; } HasCheats()125 bool HasCheats() const { return enable_cheats; } GetParamMod()126 int GetParamMod() const { return param_mod; } 127 128 sf::Music& GetCurMusic() const; 129 void StopAllMusic(); 130 131 void StartNewGame(); 132 void StartNextLevel(); 133 void ReplayLevel(int level); 134 void StartSingle(int level); 135 void StartLevelEditor(int level); 136 void ResetCamera(); 137 void StartDefault(); 138 void ResetLevel(); 139 void ResetCheats(); 140 void Synchronize(); 141 142 void UpdateMarble(float dx=0.0f, float dy=0.0f); 143 void UpdateCamera(float dx=0.0f, float dy=0.0f, float dz=0.0f, bool speedup=false); 144 145 void SnapCamera(); 146 void HideObjects(); 147 148 void Write(sf::Shader& shader) const; WriteLVL(int lvl)149 void WriteLVL(int lvl) 150 { 151 cur_level = lvl; 152 } 153 154 void WriteRenderer(Renderer & rd); 155 156 void WriteShader(ComputeShader & rd); 157 158 float DE(const Eigen::Vector3f& pt) const; 159 Eigen::Vector3f NP(const Eigen::Vector3f& pt) const; 160 bool MarbleCollision(float& delta_v); 161 162 void Cheat_ColorChange(); 163 void Cheat_FreeCamera(); 164 void Cheat_Gravity(); 165 void Cheat_HyperSpeed(); 166 void Cheat_IgnoreGoal(); 167 void Cheat_Motion(); 168 void Cheat_Planet(); 169 void Cheat_Zoom(); 170 void Cheat_Param(int param); 171 172 void ExitEditor(); 173 174 Eigen::Vector3f MouseRayCast(int mousex, int mousey, float min_dist = MIN_DIST); 175 Eigen::Vector3f RayMarch(const Eigen::Vector3f& pt, const Eigen::Vector3f& ray, float min_dist = MIN_DIST); 176 177 sf::Sound sound_goal; 178 sf::SoundBuffer buff_goal; 179 sf::Sound sound_bounce1; 180 sf::SoundBuffer buff_bounce1; 181 sf::Sound sound_bounce2; 182 sf::SoundBuffer buff_bounce2; 183 sf::Sound sound_bounce3; 184 sf::SoundBuffer buff_bounce3; 185 sf::Sound sound_shatter; 186 sf::SoundBuffer buff_shatter; 187 188 protected: 189 void SetLevel(int level); 190 191 void UpdateIntro(bool ssaver); 192 void UpdateOrbit(); 193 void UpdateDeOrbit(float dx, float dy, float dz); 194 void UpdateNormal(float dx, float dy, float dz); 195 void UpdateCameraOnly(float dx, float dy, float dz); 196 void UpdateGoal(); 197 void MakeCameraRotation(); 198 199 private: 200 float time; 201 int cur_level; 202 bool is_fullrun; 203 bool intro_needs_snap; 204 bool play_single; 205 bool level_editor; 206 207 Eigen::Matrix4f cam_mat; 208 float cam_look_x; 209 float cam_look_y; 210 float cam_dist; 211 Eigen::Vector3f cam_pos; 212 CamMode cam_mode; 213 214 float cam_look_x_smooth; 215 float cam_look_y_smooth; 216 float cam_dist_smooth; 217 Eigen::Vector3f cam_pos_smooth; 218 219 Eigen::Vector3f flag_pos; 220 221 222 int ResX, ResY; 223 int WinX, WinY; 224 int timer; 225 int final_time; 226 int sum_time; 227 float exposure; 228 229 230 231 sf::Music* music; 232 233 234 bool enable_cheats; 235 bool free_camera; 236 int gravity_type; 237 int param_mod; 238 bool ignore_goal; 239 bool hyper_speed; 240 bool disable_motion; 241 bool zoom_to_scale; 242 float gravity; 243 }; 244 245 int * GetReplayFrame(); 246 247 void StartRecording(); 248 249 void StopRecording2File(std::string path, bool save = true); 250 251 void StartReplayFromFile(std::string path); 252 void StopReplay();