Changeset 73a10ca in opengl-game for new-game.cpp
- Timestamp:
- Apr 19, 2020, 3:41:08 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 52a02e6, 845a2cb
- Parents:
- 7297892
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (04/19/20 15:30:19)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (04/19/20 15:41:08)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r7297892 r73a10ca 162 162 }; 163 163 164 /*** START OF REFACTORED CODE ***/ 164 165 void glfw_error_callback(int error, const char* description); 165 166 166 167 void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); 167 168 void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); 168 /*** START OF REFACTORED CODE ***/169 169 void window_size_callback(GLFWwindow* window, int width, int height); 170 /*** END OF REFACTORED CODE ***/171 170 172 171 void APIENTRY debugGlCallback( … … 179 178 const void* userParam 180 179 ); 180 /*** END OF REFACTORED CODE ***/ 181 181 182 182 bool faceClicked(array<vec3, 3> points, SceneObject* obj, vec4 world_ray, vec4 cam, vec4& click_point); … … 187 187 unsigned char* loadImage(string file_name, int* x, int* y); 188 188 189 /*** START OF REFACTORED CODE ***/ 189 190 void initObject(SceneObject* obj); 190 191 void addObjectToScene(SceneObject* obj, … … 192 193 map<ObjectType, ShaderModelGroup>& modelGroups, 193 194 GLuint ubo); 195 /*** END OF REFACTORED CODE ***/ 194 196 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 195 197 … … 198 200 void addModelToGroup(ShaderModelGroup& modelGroup, SceneObject& model); 199 201 202 /*** START OF REFACTORED CODE ***/ 200 203 void defineModelGroupAttrib(ShaderModelGroup& modelGroup, string name, AttribType attribType, GLint size, GLenum type, size_t fieldOffset); 201 204 void defineModelGroupUniform(ShaderModelGroup& modelGroup, string name, AttribType attribType, GLint size, UniformType type, GLfloat* data); … … 203 206 void bindUniformData(AttribInfo& attrib); 204 207 void bindUniformData(AttribInfo& attrib, GLfloat* data); 208 /*** END OF REFACTORED CODE ***/ 205 209 206 210 size_t GLsizeof(GLenum); … … 210 214 void calculateObjectBoundingBox(SceneObject* obj); 211 215 216 /*** START OF REFACTORED CODE ***/ 212 217 void populateBuffers(vector<SceneObject*>& objects, 213 218 map<GLuint, BufferInfo>& shaderBufferInfo, … … 226 231 Asteroid* createAsteroid(vec3 pos); 227 232 Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width); 233 /*** END OF REFACTORED CODE ***/ 228 234 ParticleEffect* createExplosion(mat4 model_mat); 229 235 236 /*** START OF REFACTORED CODE ***/ 230 237 void translateLaser(Laser* laser, const vec3& translation, GLuint ubo); 231 238 void updateLaserTarget(Laser* laser, vector<SceneObject*>& objects, ShaderModelGroup& laserSmg, GLuint asteroid_sp); 232 239 bool getLaserAndAsteroidIntersection(vec3& start, vec3& end, SceneObject& asteroid, vec3& intersection); 240 /*** END OF REFACTORED CODE ***/ 233 241 234 242 void renderMainMenu(); … … 253 261 bool key_down[NUM_KEYS]; 254 262 263 /*** START OF REFACTORED CODE ***/ 255 264 int windowWidth = 640; 256 265 int windowHeight = 480; … … 262 271 263 272 vector<SceneObject*> objects; 273 vector<EffectOverTime*> effects; 274 /*** END OF REFACTORED CODE ***/ 264 275 queue<Event> events; 265 vector<EffectOverTime*> effects;266 276 267 277 SceneObject* clickedObject = NULL; 268 278 SceneObject* selectedObject = NULL; 269 279 280 /*** START OF REFACTORED CODE ***/ 270 281 float NEAR_CLIP = 0.1f; 271 282 float FAR_CLIP = 100.0f; … … 274 285 bool isRunning = true; 275 286 276 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);277 278 287 Laser* leftLaser = NULL; 279 288 EffectOverTime* leftLaserEffect = NULL; … … 281 290 Laser* rightLaser = NULL; 282 291 EffectOverTime* rightLaserEffect = NULL; 292 /*** END OF REFACTORED CODE ***/ 283 293 284 294 map<string, vector<UIValue>> valueLists; 285 295 296 /*** START OF REFACTORED CODE ***/ 286 297 /* 287 298 * TODO: Asteroid and ship movement currently depend on framerate, fix this in a generic/reusable way … … 289 300 */ 290 301 291 /*** START OF REFACTORED CODE ***/292 302 // Helps to test logging during crashes 293 303 void badFunc() { … … 570 580 initModelGroupAttribs(modelGroups[TYPE_EXPLOSION]); 571 581 582 /*** START OF REFACTORED CODE ***/ 572 583 cam_pos = vec3(0.0f, 0.0f, 2.0f); 573 584 float cam_yaw = 0.0f * 2.0f * 3.14159f / 360.0f; … … 655 666 656 667 GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_LASER].shaderProgram, "models"); 668 /*** END OF REFACTORED CODE ***/ 657 669 658 670 GLuint explosion_sp_models_ub_index = glGetUniformBlockIndex(modelGroups[TYPE_EXPLOSION].shaderProgram, "models"); 659 671 660 672 673 /*** START OF REFACTORED CODE ***/ 661 674 glUseProgram(modelGroups[TYPE_SHIP].shaderProgram); 662 675 bindUniformData(modelGroups[TYPE_SHIP].attribs["view"]); … … 685 698 glUniformBlockBinding(modelGroups[TYPE_LASER].shaderProgram, laser_sp_models_ub_index, ub_binding_point); 686 699 glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE); 700 /*** END OF REFACTORED CODE ***/ 687 701 688 702 … … 769 783 if (curState == STATE_GAME) { 770 784 785 /*** START OF REFACTORED CODE ***/ 771 786 elapsed_seconds_spawn += elapsedTime; 772 787 if (elapsed_seconds_spawn > 0.5f) { … … 776 791 elapsed_seconds_spawn -= 0.5f; 777 792 } 793 /*** END OF REFACTORED CODE ***/ 778 794 779 795 /* … … 786 802 */ 787 803 804 /*** START OF REFACTORED CODE ***/ 788 805 /* 789 806 if (key_state[GLFW_KEY_SPACE] == GLFW_PRESS) { … … 861 878 862 879 removeObjectFromScene(*objects[i], ubo); 880 /*** END OF REFACTORED CODE ***/ 863 881 score++; 864 882 … … 871 889 } 872 890 } 891 /*** START OF REFACTORED CODE ***/ 873 892 } 874 893 } … … 958 977 cam_moved = false; 959 978 } 979 /*** END OF REFACTORED CODE ***/ 960 980 961 981 glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram); … … 1426 1446 } 1427 1447 1448 /*** START OF REFACTORED CODE ***/ 1428 1449 SceneObject* createShip() { 1429 1450 SceneObject* ship = new SceneObject(); … … 1896 1917 return obj; 1897 1918 } 1919 /*** END OF REFACTORED CODE ***/ 1898 1920 1899 1921 ShaderModelGroup createModelGroup(GLuint shaderProgram) { … … 1920 1942 } 1921 1943 1944 /*** START OF REFACTORED CODE ***/ 1922 1945 void defineModelGroupAttrib(ShaderModelGroup& modelGroup, string name, AttribType attribType, 1923 1946 GLint size, GLenum type, size_t fieldOffset) { … … 1938 1961 } 1939 1962 1940 /*** START OF REFACTORED CODE ***/1941 1963 void defineModelGroupUniform(ShaderModelGroup& modelGroup, string name, AttribType attribType, 1942 1964 GLint size, UniformType type, GLfloat* data) { … … 1977 1999 } 1978 2000 } 1979 /*** END OF REFACTORED CODE ***/1980 2001 1981 2002 void bindUniformData(AttribInfo& attrib) { … … 2010 2031 } 2011 2032 } 2033 /*** END OF REFACTORED CODE ***/ 2012 2034 2013 2035 /* The purpose of this function is to replace the use of sizeof() when calling … … 2393 2415 ImGui::Text("Hello, world!"); // Display some text (you can use a format string too) 2394 2416 ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f 2395 ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color2396 2417 2397 2418 ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state … … 2528 2549 } 2529 2550 2551 /*** START OF REFACTORED CODE ***/ 2530 2552 Asteroid* createAsteroid(vec3 pos) { 2531 2553 Asteroid* obj = new Asteroid(); … … 2649 2671 return obj; 2650 2672 } 2673 /*** END OF REFACTORED CODE ***/ 2651 2674 2652 2675 // TODO: Maybe pass in startTime instead of calling glfwGetTime() here
Note:
See TracChangeset
for help on using the changeset viewer.