Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Complete prototype #3

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fdde823
ecs prototype
aehmttw Oct 26, 2023
925079e
clion gitignore
nelltov Oct 26, 2023
30b9597
paintbrush and models
aehmttw Oct 26, 2023
0d1d81b
Merge branch 'main' of https://github.com/15466-magitech/magitech
nelltov Oct 27, 2023
509f6cb
clion gitignore pt2
nelltov Oct 27, 2023
69002e7
updated ECS template and EventHandler component definition
nelltov Oct 27, 2023
c1d4721
Finished ECS base, but test code segfaults
RussellEmerine Oct 28, 2023
e308dff
Fixed the segfault
RussellEmerine Oct 28, 2023
68b7d0b
EventHandler: guess Linux doesn't care, but on Mac need to include fu…
Oct 30, 2023
d06d527
Maekfile, spline: Add spline code from 15-462 adapted for glm
Oct 30, 2023
0ffb4ba
new models
aehmttw Oct 30, 2023
1b5f337
Merge branch 'main' of https://github.com/15466-magitech/magitech
aehmttw Oct 30, 2023
71100f4
Rebased the project on walkmesh game5, rather than multiplayer game6
RussellEmerine Oct 30, 2023
0b8560b
Merge pull request #1 from 15466-magitech/rebase-to-game5
RussellEmerine Oct 30, 2023
4706d5a
Maekfile: readd spline
Oct 30, 2023
9027691
meshcoord: Proposed universe coordinates based on the existence of se…
Oct 30, 2023
148ced2
main: set quit key to q and print screen key to p
Oct 30, 2023
931cd83
new models
aehmttw Oct 30, 2023
a09eb6f
couple of house models
nelltov Oct 30, 2023
46eeb50
a wizard appears
aehmttw Oct 30, 2023
b368999
Merge branch 'main' of https://github.com/15466-magitech/magitech
aehmttw Oct 30, 2023
7e66525
fixed wizard positioning
aehmttw Oct 31, 2023
19f3993
fixed wizard scaling
aehmttw Oct 31, 2023
f16fc74
fixed wizard scaling
aehmttw Oct 31, 2023
a21c1c8
Update houses.blend
nelltov Oct 31, 2023
f250c52
journal
aehmttw Oct 31, 2023
9e2d211
Merge branch 'main' of https://github.com/15466-magitech/magitech
aehmttw Oct 31, 2023
05e1f70
PlayMode: Add wizard to scene, offset camera
Oct 31, 2023
1bc3dd8
art world compiled in blender scene
nelltov Oct 31, 2023
1fc2eef
Merge branch 'main' of https://github.com/15466-magitech/magitech
nelltov Oct 31, 2023
3c323e8
Entity: need to include functional
Oct 31, 2023
93d7748
wizard: add pcnt file
Oct 31, 2023
d96ccf9
Collision Detection & Wireframe Rendering
chongchong721 Oct 31, 2023
235e267
art world
aehmttw Oct 31, 2023
5ff2793
Merge branch 'main' of https://github.com/15466-magitech/magitech
aehmttw Oct 31, 2023
85f58eb
gitignore: DS_Store
Oct 31, 2023
a80e2b5
PlayMode: insert cube test artifact into scene
Oct 31, 2023
6e50775
Collider/wireframe Initialization functions
chongchong721 Oct 31, 2023
ec1fd6d
art world updated
aehmttw Oct 31, 2023
1724ddd
Merge branch 'main' of https://github.com/15466-magitech/magitech
aehmttw Oct 31, 2023
f390574
Update artworld_scene.blend
nelltov Oct 31, 2023
b0d6124
Testscene with wireframe logics(space to interact)
chongchong721 Oct 31, 2023
b94b088
art world updated
aehmttw Oct 31, 2023
b6f717b
art world updated with signs
aehmttw Oct 31, 2023
12c87e9
col_unlock_firstdoor
aehmttw Oct 31, 2023
4d23370
export
aehmttw Oct 31, 2023
2379270
Made a terminal that displays text in a monospace font
RussellEmerine Oct 31, 2023
7159d4b
Merge branch 'main' into terminal
RussellEmerine Oct 31, 2023
08ae016
Merge pull request #3 from 15466-magitech/terminal
RussellEmerine Oct 31, 2023
541b5cd
Made first-draft interface for Terminal to recognize entered commands
RussellEmerine Oct 31, 2023
8c30d77
Merge pull request #4 from 15466-magitech/terminal
RussellEmerine Oct 31, 2023
865dfe6
Update scenes / Remove walkmesh from drawable
chongchong721 Oct 31, 2023
dca75df
Made a terminal that displays text in a monospace font
RussellEmerine Oct 31, 2023
ca1296d
art world updated
aehmttw Oct 31, 2023
974ddd6
PlayMode: insert cube test artifact into scene
Oct 31, 2023
7983414
export
aehmttw Oct 31, 2023
de2eeb1
Made first-draft interface for Terminal to recognize entered commands
RussellEmerine Oct 31, 2023
5fadbb3
Collider/wireframe Initialization functions
chongchong721 Oct 31, 2023
6470a76
Testscene with wireframe logics(space to interact)
chongchong721 Oct 31, 2023
abb49ab
delete repeated code line
chongchong721 Oct 31, 2023
50d0969
integrate unlock/paintbrugh into terminal logics
chongchong721 Oct 31, 2023
b81cb18
gitignore: remove extra DS_Store
Oct 31, 2023
80117bc
PlayMode: keep ref to textFace, add read key, start animation on read
Oct 31, 2023
917ec7b
Keep Player Normal (0,0,1). Increase player speed
chongchong721 Oct 31, 2023
70602ab
Merged wireframes and main
RussellEmerine Oct 31, 2023
5006021
Merge branch 'main' into complete_prototype
RussellEmerine Oct 31, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ dist/freetype-test*
scenes/show-meshes*
scenes/show-scene*
*.blend[0-9]
CMakeLists.txt
cmake-build-debug/
.idea/
.vscode/
.DS_STORE
1 change: 1 addition & 0 deletions ECS/Component.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Component.hpp"
12 changes: 12 additions & 0 deletions ECS/Component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <cstdlib>
#include <unordered_map>

template<typename T>
struct Component {
static std::unordered_map<uint32_t, T> &get_map() {
static std::unordered_map<uint32_t, T> map;
return map;
};
};
9 changes: 9 additions & 0 deletions ECS/Components/EventHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <functional>
#include "EventHandler.hpp"

EventHandler::EventHandler(const std::function<bool(const SDL_Event &, const glm::uvec2 &)> &f)
: handler(f) {}

bool EventHandler::handle_event(const SDL_Event &evt, const glm::uvec2 &move) {
return handler(evt, move);
}
23 changes: 23 additions & 0 deletions ECS/Components/EventHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Created by Nellie Tonev on 10/27/23.
* Author(s): Nellie Tonev, Russell Emerine
*
* Component that corresponds to PlayMode::handle_event
*/
#pragma once

#include <cstdlib>
#include <unordered_map>

#include <SDL.h>
#include <glm/glm.hpp>
#include "../Component.hpp"

struct EventHandler : Component<EventHandler> {
explicit EventHandler(const std::function<bool(SDL_Event const &, glm::uvec2 const &)> &f);

bool handle_event(SDL_Event const &evt, glm::uvec2 const &window_size);

private:
const std::function<bool(SDL_Event const &, glm::uvec2 const &)> &handler;
};
21 changes: 21 additions & 0 deletions ECS/Entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Created by Matei Budiu on 10/26/23.
* Author(s): Nellie Tonev
*
* Adapted from Entity code covered in class on 10/24/23.
*/

#include "Entity.hpp"

Entity::Entity() {
/* create unique id for entity lookup */
static uint32_t unique_id = 0;
id = unique_id;
unique_id++;
}

Entity::~Entity() {
for (auto &[_, f]: to_delete) {
f();
}
}
73 changes: 73 additions & 0 deletions ECS/Entity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Created by Matei Budiu on 10/26/23.
* Author(s): Matei Budiu, Russell Emerine, Nellie Tonev
*/
#pragma once

#include <cstdlib>
#include <unordered_map>
#include <typeindex>
#include <iostream>
#include <functional>

struct Entity {
Entity();

/*
* Destruct the entity by removing all components that haven't yet been removed
*/
~Entity();

/*
* Unique identity for querying and deleting entities, generated uniquely in the constructor
*/
uint32_t id;

/*
* Associate a component with this entity, update map of entities with component T
*/
template<typename T, typename... Args>
T &add_component(Args &&... args) {
to_delete[std::type_index(typeid(T))] = [this]() {
// I don't just call remove_component because that invalidates the iterator in ~Entity
std::unordered_map<uint32_t, T> &entity_to_component = T::get_map();
entity_to_component.erase(id);
};

std::unordered_map<uint32_t, T> &entity_to_component = T::get_map();
// this call to emplace looks weird but I'm pretty sure it's correct
return entity_to_component.emplace(
std::piecewise_construct,
std::forward_as_tuple(id),
std::forward_as_tuple(args...)
).first->second;
}

/*
* Look up a component associated with this entity
*/
template<typename T>
T *get_component() {
std::unordered_map<uint32_t, T> &entity_to_component = T::get_map();
auto f = entity_to_component.find(id);
if (f == entity_to_component.end()) return nullptr;
else return &f->second;
}

/*
* Remove a component associated with this entity (if the entity has the component)
*/
template<typename T>
void remove_component() {
to_delete.erase(std::type_index(typeid(T)));

std::unordered_map<uint32_t, T> &entity_to_component = T::get_map();
entity_to_component.erase(id);
}

private:
/*
* Keep track of what components to delete upon destruction
*/
std::unordered_map<std::type_index, std::function<void()>> to_delete;
};
17 changes: 17 additions & 0 deletions ECS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ECS Documentation
## **Entity**
A container of components corresponding to objects and elements of the game.
Classes for game objects (e.g., Player) should include a function to create an entity
representing the data that the main game loop needs.

## **Components**
Define a new component type for any functionality that is shared between game objects
of different classes. Keep track of component definitions and
any implementation notes below.

### EventHandler
Add to any entities that handle user inputs (e.g., Player and Terminal).
After attaching the EventHandler component, make sure to update its handle_event() function appropriately.
Edit the main loop to check if the event is handled across any of the entities with this component.

## **Systems**
11 changes: 10 additions & 1 deletion LitColorTextureProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Load< LitColorTextureProgram > lit_color_texture_program(LoadTagEarly, []() -> L
lit_color_texture_program_pipeline.OBJECT_TO_CLIP_mat4 = ret->OBJECT_TO_CLIP_mat4;
lit_color_texture_program_pipeline.OBJECT_TO_LIGHT_mat4x3 = ret->OBJECT_TO_LIGHT_mat4x3;
lit_color_texture_program_pipeline.NORMAL_TO_LIGHT_mat3 = ret->NORMAL_TO_LIGHT_mat3;
lit_color_texture_program_pipeline.draw_frame = ret->draw_frame;

/* This will be used later if/when we build a light loop into the Scene:
lit_color_texture_program_pipeline.LIGHT_TYPE_int = ret->LIGHT_TYPE_int;
Expand Down Expand Up @@ -80,6 +81,7 @@ LitColorTextureProgram::LitColorTextureProgram() {
"in vec4 color;\n"
"in vec2 texCoord;\n"
"out vec4 fragColor;\n"
"uniform bool wireframe;\n"
"void main() {\n"
" vec3 n = normalize(normal);\n"
" vec3 e;\n"
Expand All @@ -103,7 +105,12 @@ LitColorTextureProgram::LitColorTextureProgram() {
" e = max(0.0, dot(n,-LIGHT_DIRECTION)) * LIGHT_ENERGY;\n"
" }\n"
" vec4 albedo = texture(TEX, texCoord) * color;\n"
" fragColor = vec4(e*albedo.rgb, albedo.a);\n"
" if(wireframe){\n"
" fragColor = vec4(0.0,0.0,0.0,1.0);\n"
" }\n"
" else{\n"
" fragColor = vec4(e*albedo.rgb, 1.0);\n"
" }\n"
"}\n"
);
//As you can see above, adjacent strings in C/C++ are concatenated.
Expand All @@ -126,6 +133,8 @@ LitColorTextureProgram::LitColorTextureProgram() {
LIGHT_ENERGY_vec3 = glGetUniformLocation(program, "LIGHT_ENERGY");
LIGHT_CUTOFF_float = glGetUniformLocation(program, "LIGHT_CUTOFF");

draw_frame = glGetUniformLocation(program,"wireframe");


GLuint TEX_sampler2D = glGetUniformLocation(program, "TEX");

Expand Down
3 changes: 3 additions & 0 deletions LitColorTextureProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct LitColorTextureProgram {
GLuint LIGHT_DIRECTION_vec3 = -1U;
GLuint LIGHT_ENERGY_vec3 = -1U;
GLuint LIGHT_CUTOFF_float = -1U;

//Wireframe drawing
GLuint draw_frame = -1U;

//Textures:
//TEXTURE0 - texture that is accessed by TexCoord
Expand Down
Loading