Turned on warnings and fixed
This commit is contained in:
parent
76985519f1
commit
87df6921e8
17
Makefile
17
Makefile
|
@ -10,7 +10,7 @@ endif
|
|||
UNAME_P != uname -m
|
||||
|
||||
#CC specifies which compiler we're using
|
||||
CC = clang
|
||||
CC = clang -std=c99
|
||||
CXX = clang++
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
|
@ -58,7 +58,7 @@ ehead != $(call findindir,./source/engine,*.h)
|
|||
eobjects != $(call make_objs, ./source/engine)
|
||||
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine.c yugine.c)
|
||||
|
||||
imguisrcs = imgui imgui_draw imgui_widgets imgui_tables backends/imgui_impl_sdl backends/imgui_impl_opengl3
|
||||
imguisrcs = imgui imgui_draw imgui_widgets imgui_tables backends/imgui_impl_glfw backends/imgui_impl_opengl3
|
||||
imguiobjs != $(call prefix,$(imguisrcs),$(objprefix)/source/editor/imgui/,.o)
|
||||
|
||||
eddirs != find ./source/editor -type d
|
||||
|
@ -79,8 +79,8 @@ includeflag != $(call prefix,$(edirs) $(eddirs) $(pindirs) $(bsdirs),-I)
|
|||
COMPINCLUDE = $(edirs) $(eddirs) $(pindirs) $(bsdirs)
|
||||
|
||||
#COMPILER_FLAGS specifies the additional compilation options we're using
|
||||
WARNING_FLAGS = -w #-pedantic -Wall -Wextra -Wwrite-strings
|
||||
COMPILER_FLAGS = $(includeflag) -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -c -MMD -MP $< -o $@
|
||||
WARNING_FLAGS = -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
|
||||
COMPILER_FLAGS = $(includeflag) -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c -MMD -MP $< -o $@
|
||||
|
||||
LIBPATH = -L./bin
|
||||
|
||||
|
@ -93,7 +93,7 @@ ifeq ($(UNAME), Windows_NT)
|
|||
else
|
||||
LINKER_FLAGS =
|
||||
ELIBS = editor engine
|
||||
CLIBS = SDL2 SDL2_mixer GLEW GL dl pthread
|
||||
CLIBS = glfw SDL2 SDL2_mixer dl pthread
|
||||
EXT =
|
||||
endif
|
||||
|
||||
|
@ -119,10 +119,13 @@ LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
|
|||
engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
|
||||
@echo Linking engine
|
||||
@$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
||||
@echo Finished build
|
||||
|
||||
editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
|
||||
@echo Linking editor
|
||||
$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
||||
@mv editor yugine/editor
|
||||
@echo Finished build
|
||||
|
||||
$(ENGINE): $(eobjects)
|
||||
@echo Making library engine.a
|
||||
|
@ -147,12 +150,12 @@ pinball: $(ENGINE) $(pinobjects)
|
|||
$(objprefix)/%.o:%.cpp
|
||||
@mkdir -p $(@D)
|
||||
@echo Making C++ object $@
|
||||
@$(CXX) $(COMPILER_FLAGS)
|
||||
-@$(CXX) $(COMPILER_FLAGS)
|
||||
|
||||
$(objprefix)/%.o:%.c
|
||||
@mkdir -p $(@D)
|
||||
@echo Making C object $@
|
||||
@$(CC) $(COMPILER_FLAGS)
|
||||
-@$(CC) $(COMPILER_FLAGS)
|
||||
|
||||
clean:
|
||||
@echo Cleaning project
|
||||
|
|
|
@ -5,4 +5,4 @@ unsigned long long triCount = 0;
|
|||
void resetTriangles()
|
||||
{
|
||||
triCount = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
extern "C" {
|
||||
#include "openglrender.h"
|
||||
#include "editor.h"
|
||||
#include "window.h"
|
||||
#include "resources.h"
|
||||
|
@ -12,7 +13,6 @@ extern "C" {
|
|||
#include "editorstate.h"
|
||||
#include <stdlib.h>
|
||||
#include "input.h"
|
||||
#include "openglrender.h"
|
||||
#include "2dphysics.h"
|
||||
#include "debugdraw.h"
|
||||
#include "level.h"
|
||||
|
@ -20,7 +20,6 @@ extern "C" {
|
|||
#include "sprite.h"
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "math.h"
|
||||
#include <GL/glew.h>
|
||||
#include <ftw.h>
|
||||
#include <ctype.h>
|
||||
#include "pinball.h"
|
||||
|
@ -32,20 +31,13 @@ extern "C" {
|
|||
#include <stb_ds.h>
|
||||
#define ASSET_TEXT_BUF 1024*1024 /* 1 MB buffer for editing text files */
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
struct gameproject *cur_project;
|
||||
struct vec *projects;
|
||||
static char setpath[MAXPATH];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Menus
|
||||
// TODO: Pack this into a bitfield
|
||||
static struct editorVars editor = { 0 };
|
||||
|
@ -55,14 +47,11 @@ bool flashlightOn = false;
|
|||
// Lighting effect flags
|
||||
static bool renderAO = true;
|
||||
static bool renderDynamicShadows = true;
|
||||
static bool renderRefraction = true;
|
||||
static bool renderReflection = true;
|
||||
|
||||
// Debug render modes
|
||||
static bool renderGizmos = false;
|
||||
static bool showGrid = true;
|
||||
static bool debugDrawPhysics = false;
|
||||
static bool renderNav = false;
|
||||
|
||||
const char *allowed_extensions[] = { "jpg", "png", "gltf", "glsl" };
|
||||
|
||||
|
@ -79,10 +68,6 @@ struct fileasset *selected_asset;
|
|||
|
||||
static int selected_index = -1;
|
||||
|
||||
static struct mCamera camera = { 0 };
|
||||
|
||||
static int tex_view = 0;
|
||||
|
||||
static int grid1_width = 1;
|
||||
static int grid1_span = 100;
|
||||
static int grid2_width = 3;
|
||||
|
@ -260,6 +245,155 @@ void editor_save()
|
|||
fclose(feditor);
|
||||
}
|
||||
|
||||
static void edit_input_cb(GLFWwindow *w, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (editor_wantkeyboard()) return;
|
||||
|
||||
switch (key) {
|
||||
case GLFW_KEY_ESCAPE:
|
||||
quit = true;
|
||||
editor_save_projects();
|
||||
editor_save();
|
||||
break;
|
||||
|
||||
case GLFW_KEY_1:
|
||||
renderMode = LIT;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_2:
|
||||
renderMode = UNLIT;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_3:
|
||||
renderMode = WIREFRAME;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_4:
|
||||
renderMode = DIRSHADOWMAP;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_5:
|
||||
renderGizmos = !renderGizmos;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_6:
|
||||
debugDrawPhysics = !debugDrawPhysics;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_7:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_8:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_9:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_0:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_T:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F2:
|
||||
editor.showAssetMenu = !editor.showAssetMenu;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F3:
|
||||
editor.showStats = !editor.showStats;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F4:
|
||||
editor.showHierarchy = !editor.showHierarchy;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F5:
|
||||
editor.showLighting = !editor.showLighting;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F6:
|
||||
editor.showGameSettings = !editor.showGameSettings;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F7:
|
||||
editor.showViewmode = !editor.showViewmode;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F8:
|
||||
editor.showDebugMenu = !editor.showDebugMenu;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F9:
|
||||
editor.showExport = !editor.showExport;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F10:
|
||||
editor.showLevel = !editor.showLevel;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F11:
|
||||
window_togglefullscreen(mainwin);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_GRAVE_ACCENT:
|
||||
editor.showREPL = !editor.showREPL;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_K:
|
||||
showGrid = !showGrid;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_DELETE:
|
||||
break;
|
||||
|
||||
case GLFW_KEY_F:
|
||||
/*
|
||||
if (selectedobject != NULL) {
|
||||
cam_goto_object(&camera, &selectedobject->transform);
|
||||
}
|
||||
*/
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void edit_mouse_cb(GLFWwindow *w, int button, int action, int mods)
|
||||
{
|
||||
if (editor_wantkeyboard()) return;
|
||||
|
||||
if (action == GLFW_PRESS) {
|
||||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
cursor_hide();
|
||||
break;
|
||||
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
/*
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, debugColorPickBO);
|
||||
int mx = 0;
|
||||
int my = 0;
|
||||
SDL_GetMouseState(&mx, &my);
|
||||
unsigned char data[4];
|
||||
glReadPixels(mx, SCREEN_HEIGHT - my, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
int pickID = data[0] + data[1]*256 + data[2]*256*256;
|
||||
snprintf(objectName, 200, "Object %d", pickID);
|
||||
pickGameObject(pickID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
*/
|
||||
|
||||
pickGameObject(-1);
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
cursor_show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void editor_init(struct mSDLWindow *window)
|
||||
{
|
||||
projects = vec_make(sizeof(struct gameproject), 5);
|
||||
|
@ -276,197 +410,24 @@ void editor_init(struct mSDLWindow *window)
|
|||
|
||||
|
||||
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO & io = ImGui::GetIO();
|
||||
(void) io;
|
||||
ImGui::StyleColorsClassic();
|
||||
ImGui_ImplSDL2_InitForOpenGL(window->window, window->glContext);
|
||||
ImGui_ImplGlfw_InitForOpenGL(window->window, true);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
glfwSetKeyCallback(window->window, edit_input_cb);
|
||||
glfwSetMouseButtonCallback(window->window, edit_mouse_cb);
|
||||
}
|
||||
|
||||
void editor_input(struct mSDLWindow *window, SDL_Event * e)
|
||||
void editor_input()
|
||||
{
|
||||
ImGui_ImplSDL2_ProcessEvent(e);
|
||||
io = &ImGui::GetIO();
|
||||
|
||||
|
||||
//User requests quit
|
||||
if (e->type == SDL_QUIT) {
|
||||
quit = true;
|
||||
}
|
||||
//Handle keypress with current mouse position
|
||||
else if (!editor_wantkeyboard() && e->type == SDL_KEYDOWN) {
|
||||
switch (e->key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
quit = true;
|
||||
editor_save_projects();
|
||||
editor_save();
|
||||
break;
|
||||
|
||||
case SDLK_1:
|
||||
renderMode = LIT;
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
renderMode = UNLIT;
|
||||
break;
|
||||
|
||||
case SDLK_3:
|
||||
renderMode = WIREFRAME;
|
||||
break;
|
||||
|
||||
case SDLK_4:
|
||||
renderMode = DIRSHADOWMAP;
|
||||
break;
|
||||
|
||||
case SDLK_5:
|
||||
renderGizmos = !renderGizmos;
|
||||
break;
|
||||
|
||||
case SDLK_6:
|
||||
debugDrawPhysics = !debugDrawPhysics;
|
||||
break;
|
||||
|
||||
case SDLK_7:
|
||||
break;
|
||||
|
||||
case SDLK_8:
|
||||
break;
|
||||
|
||||
case SDLK_9:
|
||||
break;
|
||||
|
||||
case SDLK_0:
|
||||
break;
|
||||
|
||||
case SDLK_t:
|
||||
break;
|
||||
|
||||
case SDLK_F2:
|
||||
editor.showAssetMenu = !editor.showAssetMenu;
|
||||
break;
|
||||
|
||||
case SDLK_F3:
|
||||
editor.showStats = !editor.showStats;
|
||||
break;
|
||||
|
||||
case SDLK_F4:
|
||||
editor.showHierarchy = !editor.showHierarchy;
|
||||
break;
|
||||
|
||||
case SDLK_F5:
|
||||
editor.showLighting = !editor.showLighting;
|
||||
break;
|
||||
|
||||
case SDLK_F6:
|
||||
editor.showGameSettings = !editor.showGameSettings;
|
||||
break;
|
||||
|
||||
case SDLK_F7:
|
||||
editor.showViewmode = !editor.showViewmode;
|
||||
break;
|
||||
|
||||
case SDLK_F8:
|
||||
editor.showDebugMenu = !editor.showDebugMenu;
|
||||
break;
|
||||
|
||||
case SDLK_F9:
|
||||
editor.showExport = !editor.showExport;
|
||||
break;
|
||||
|
||||
case SDLK_F10:
|
||||
editor.showLevel = !editor.showLevel;
|
||||
break;
|
||||
|
||||
case SDLK_F11:
|
||||
window_togglefullscreen(window);
|
||||
break;
|
||||
|
||||
case SDLK_BACKQUOTE:
|
||||
editor.showREPL = !editor.showREPL;
|
||||
break;
|
||||
|
||||
case SDLK_k:
|
||||
showGrid = !showGrid;
|
||||
break;
|
||||
|
||||
case SDLK_DELETE:
|
||||
break;
|
||||
|
||||
case SDLK_f:
|
||||
/*
|
||||
if (selectedobject != NULL) {
|
||||
cam_goto_object(&camera, &selectedobject->transform);
|
||||
}
|
||||
*/
|
||||
break;
|
||||
|
||||
};
|
||||
} else if (!editor_wantkeyboard() && e->type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (selectedobject != NULL) {
|
||||
switch (e->key.keysym.sym) {
|
||||
case SDLK_g:
|
||||
// handle translate
|
||||
break;
|
||||
|
||||
case SDLK_r:
|
||||
break;
|
||||
|
||||
case SDLK_t:
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (e->button.button) {
|
||||
case SDL_BUTTON_RIGHT:
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
break;
|
||||
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
/*
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, debugColorPickBO);
|
||||
int mx = 0;
|
||||
int my = 0;
|
||||
SDL_GetMouseState(&mx, &my);
|
||||
unsigned char data[4];
|
||||
glReadPixels(mx, SCREEN_HEIGHT - my, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
int pickID = data[0] + data[1]*256 + data[2]*256*256;
|
||||
snprintf(objectName, 200, "Object %d", pickID);
|
||||
pickGameObject(pickID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
*/
|
||||
|
||||
pickGameObject(-1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (!editor_wantkeyboard() && e->type == SDL_MOUSEBUTTONUP) {
|
||||
switch (e->button.button) {
|
||||
case SDL_BUTTON_RIGHT:
|
||||
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_WarpMouseInWindow(window->window, SCREEN_WIDTH / 2.f,
|
||||
SCREEN_HEIGHT / 2.f);
|
||||
break;
|
||||
}
|
||||
} else if (e->type == SDL_MOUSEWHEEL) {
|
||||
mouseWheelY = e->wheel.y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SDL_GetRelativeMouseState(&xchange, &ychange);
|
||||
|
||||
if (SDL_GetRelativeMouseMode()) {
|
||||
// camera_update(&camera, xchange, ychange, currentKeyStates, mouseWheelY, deltaT);
|
||||
}
|
||||
}
|
||||
|
||||
int editor_wantkeyboard()
|
||||
{
|
||||
if (io == NULL) return 0;
|
||||
return io->WantCaptureKeyboard;
|
||||
}
|
||||
|
||||
|
@ -589,7 +550,7 @@ void editor_project_gui()
|
|||
if (editor.showStats) {
|
||||
ImGui::Begin("Stats", &editor.showStats);
|
||||
ImGui::Text("FPS: %2.4f", 1.f / deltaT);
|
||||
ImGui::Text("Triangles rendered: %d", triCount);
|
||||
ImGui::Text("Triangles rendered: %llu", triCount);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
@ -789,7 +750,7 @@ void editor_project_gui()
|
|||
void editor_render()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
|
||||
|
@ -817,7 +778,7 @@ void pickGameObject(int pickID)
|
|||
|
||||
int is_allowed_extension(const char *ext)
|
||||
{
|
||||
for (int i = 0;
|
||||
for (size_t i = 0;
|
||||
i < sizeof(allowed_extensions) / sizeof(allowed_extensions[0]);
|
||||
i++) {
|
||||
if (!strcmp(ext + 1, allowed_extensions[i]))
|
||||
|
@ -1019,7 +980,7 @@ void editor_project_btn_gui(struct gameproject *gp)
|
|||
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(gp->path);
|
||||
ImGui::Text("%s", gp->path);
|
||||
}
|
||||
|
||||
void editor_proj_select_gui()
|
||||
|
@ -1053,7 +1014,7 @@ void editor_init_project(struct gameproject *gp)
|
|||
|
||||
void editor_make_project(char *path)
|
||||
{
|
||||
FILE *f = path_open("%s%s", "w", path, "/project.yugh");
|
||||
FILE *f = path_open("w", "%s%s", path, "/project.yugh");
|
||||
cur_project =
|
||||
(struct gameproject *) malloc(sizeof(struct gameproject));
|
||||
strncpy(cur_project->name, "New Game", 127);
|
||||
|
@ -1069,7 +1030,7 @@ void editor_make_project(char *path)
|
|||
|
||||
void editor_import_project(char *path)
|
||||
{
|
||||
FILE *f = path_open("%s%s", "r", path, "/project.yugh");
|
||||
FILE *f = path_open("r", "%s%s", path, "/project.yugh");
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
|
@ -1133,7 +1094,7 @@ void staticactor_gui(struct mStaticActor *sa)
|
|||
object_gui(&sa->obj);
|
||||
if (ImGui::CollapsingHeader("Model")) {
|
||||
ImGui::Checkbox("Cast Shadows", &sa->castShadows);
|
||||
ImGui::Text("Model path", &sa->currentModelPath);
|
||||
ImGui::Text("Model path: %s", sa->currentModelPath);
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Load model")) {
|
||||
|
@ -1237,10 +1198,6 @@ void object_gui(struct mGameObject *go)
|
|||
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define EDITOR_H
|
||||
|
||||
#include <config.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include "resources.h"
|
||||
|
||||
|
@ -41,12 +40,13 @@ struct gameproject {
|
|||
};
|
||||
|
||||
struct Texture;
|
||||
struct mSDLWindow;
|
||||
|
||||
void pickGameObject(int pickID);
|
||||
int is_allowed_extension(const char *ext);
|
||||
|
||||
void editor_init(struct mSDLWindow *window);
|
||||
void editor_input(struct mSDLWindow *window, SDL_Event * e);
|
||||
void editor_input();
|
||||
void editor_render();
|
||||
int editor_wantkeyboard();
|
||||
void editor_save();
|
||||
|
@ -77,6 +77,21 @@ void game_pause();
|
|||
|
||||
void get_levels();
|
||||
|
||||
struct mLight;
|
||||
struct mPointLight;
|
||||
struct mSpotLight;
|
||||
struct mStaticActor;
|
||||
struct mTransform;
|
||||
struct mGameObject;
|
||||
struct mSprite;
|
||||
struct phys2d_circle;
|
||||
struct phys2d_segment;
|
||||
struct phys2d_box;
|
||||
struct phys2d_edge;
|
||||
struct phys2d_shape;
|
||||
struct phys2d_poly;
|
||||
struct flipper;
|
||||
|
||||
///////// Object GUIs
|
||||
void light_gui(struct mLight *light);
|
||||
void pointlight_gui(struct mPointLight *light);
|
||||
|
|
|
@ -98,9 +98,6 @@ struct phys2d_box *Make2DBox(struct mGameObject *go)
|
|||
|
||||
void phys2d_boxinit(struct phys2d_box *box, struct mGameObject *go)
|
||||
{
|
||||
cpVect verts[4] =
|
||||
{ { -5.f, -5.f }, { 5.f, -5.f }, { 5.f, 5.f }, { -5.f, 5.f } };
|
||||
cpTransform T = { 0 };
|
||||
box->shape.shape =
|
||||
cpSpaceAddShape(space,
|
||||
cpBoxShapeNew(go->body, box->w, box->h, box->r));
|
||||
|
@ -291,7 +288,6 @@ void phys2d_dbgdrawcircle(struct phys2d_circle *circle)
|
|||
void phys2d_dbgdrawseg(struct phys2d_segment *seg)
|
||||
{
|
||||
cpVect p = cpBodyGetPosition(seg->shape.go->body);
|
||||
float s = seg->shape.go->scale;
|
||||
cpVect a = cpSegmentShapeGetA(seg->shape.shape);
|
||||
cpVect b = cpSegmentShapeGetB(seg->shape.shape);
|
||||
|
||||
|
@ -329,7 +325,6 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly)
|
|||
|
||||
float s = poly->shape.go->scale;
|
||||
for (int i = 0; i < poly->n; i++) {
|
||||
float point[2];
|
||||
float d =
|
||||
sqrt(pow(poly->points[i * 2] * s, 2.f) +
|
||||
pow(poly->points[i * 2 + 1] * s, 2.f));
|
||||
|
@ -362,7 +357,6 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
|
|||
float angle = cpBodyGetAngle(edge->shape.go->body);
|
||||
|
||||
for (int i = 0; i < edge->n; i++) {
|
||||
float point[2];
|
||||
float d =
|
||||
sqrt(pow(edge->points[i * 2] * s, 2.f) +
|
||||
pow(edge->points[i * 2 + 1] * s, 2.f));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef THREEDPHYSICS_H
|
||||
#define THREEDPHYSICS_H
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "gameobject.h"
|
||||
#include "input.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
|
||||
const float CAMERA_MINSPEED = 1.f;
|
||||
const float CAMERA_MAXSPEED = 300.f;
|
||||
|
@ -41,20 +41,18 @@ mfloat_t *getviewmatrix(mfloat_t view[16],
|
|||
|
||||
void camera_2d_update(struct mCamera *camera, float deltaT)
|
||||
{
|
||||
static mfloat_t holdvec[3];
|
||||
static mfloat_t frame[3];
|
||||
vec3_zero(frame);
|
||||
|
||||
if (currentKeystates[SDL_SCANCODE_W])
|
||||
if (action_down(GLFW_KEY_W))
|
||||
vec3_add(frame, frame, UP);
|
||||
if (currentKeystates[SDL_SCANCODE_S])
|
||||
if (action_down(GLFW_KEY_S))
|
||||
vec3_add(frame, frame, DOWN);
|
||||
if (currentKeystates[SDL_SCANCODE_A])
|
||||
if (action_down(GLFW_KEY_A))
|
||||
vec3_add(frame, frame, LEFT);
|
||||
if (currentKeystates[SDL_SCANCODE_D])
|
||||
if (action_down(GLFW_KEY_D))
|
||||
vec3_add(frame, frame, RIGHT);
|
||||
|
||||
float speedMult = currentKeystates[SDL_SCANCODE_LSHIFT] ? 2.f : 1.f;
|
||||
float speedMult = action_down(GLFW_KEY_LEFT_SHIFT) ? 2.f : 1.f;
|
||||
|
||||
if (!vec3_is_zero(frame)) {
|
||||
vec3_normalize(frame, frame);
|
||||
|
|
|
@ -18,4 +18,4 @@
|
|||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "datastream.h"
|
||||
|
||||
#include <pl_mpeg.h>
|
||||
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include "shader.h"
|
||||
#include "resources.h"
|
||||
#include <GL/glew.h>
|
||||
#include "sound.h"
|
||||
#include <stdbool.h>
|
||||
#include "log.h"
|
||||
|
||||
static void ds_update_texture(uint32_t unit, uint32_t texture,
|
||||
plm_plane_t * plane)
|
||||
|
@ -30,11 +30,10 @@ static void render_audio(plm_t * mpeg, plm_samples_t * samples, void *user)
|
|||
{
|
||||
struct datastream *ds = (struct datastream *) user;
|
||||
int size = sizeof(float) * samples->count * 2;
|
||||
SDL_QueueAudio(ds->audio_device, samples->interleaved, size);
|
||||
play_raw(ds->audio_device, samples->interleaved, size);
|
||||
}
|
||||
|
||||
void ds_openvideo(struct datastream *ds, const char *video,
|
||||
const char *adriver)
|
||||
void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
||||
{
|
||||
ds_stop(ds);
|
||||
char buf[MAXPATH] = {'\0'};
|
||||
|
@ -42,12 +41,10 @@ void ds_openvideo(struct datastream *ds, const char *video,
|
|||
ds->plm = plm_create_with_filename(buf);
|
||||
|
||||
if (!ds->plm) {
|
||||
SDL_Log("Couldn't open %s", video);
|
||||
YughLog(0, 0, "Couldn't open %s", video);
|
||||
}
|
||||
|
||||
int samplerate = plm_get_samplerate(ds->plm);
|
||||
|
||||
SDL_Log("Opened %s - framerate: %f, samplerate: %d, duration: %f",
|
||||
YughLog(0, 0, "Opened %s - framerate: %f, samplerate: %d, duration: %f",
|
||||
video,
|
||||
plm_get_framerate(ds->plm),
|
||||
plm_get_samplerate(ds->plm), plm_get_duration(ds->plm)
|
||||
|
@ -59,24 +56,6 @@ void ds_openvideo(struct datastream *ds, const char *video,
|
|||
|
||||
plm_set_audio_enabled(ds->plm, true);
|
||||
plm_set_audio_stream(ds->plm, 0);
|
||||
SDL_AudioSpec audio_spec;
|
||||
SDL_memset(&audio_spec, 0, sizeof(audio_spec));
|
||||
audio_spec.freq = samplerate;
|
||||
audio_spec.format = AUDIO_F32;
|
||||
audio_spec.channels = 2;
|
||||
audio_spec.samples = 4096;
|
||||
|
||||
ds->audio_device =
|
||||
SDL_OpenAudioDevice(adriver, 0, &audio_spec, NULL, 0);
|
||||
printf("Opened audio device %d on driver %s\n", ds->audio_device,
|
||||
adriver);
|
||||
// if (audio_device == 0) {
|
||||
// SDL_Log("Failed to open audio device: %s", SDL_GetError());
|
||||
// }
|
||||
SDL_PauseAudioDevice(ds->audio_device, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
// Adjust the audio lead time according to the audio_spec buffer size
|
||||
//plm_set_audio_lead_time(plm, (double)audio_spec.samples / (double)samplerate);
|
||||
|
@ -127,7 +106,7 @@ void ds_advance(struct datastream *ds, uint32_t ms)
|
|||
|
||||
void ds_seek(struct datastream *ds, uint32_t time)
|
||||
{
|
||||
SDL_ClearQueuedAudio(0);
|
||||
clear_raw(ds->audio_device);
|
||||
plm_seek(ds->plm, time, false);
|
||||
}
|
||||
|
||||
|
@ -151,7 +130,7 @@ void ds_stop(struct datastream *ds)
|
|||
ds->plm = NULL;
|
||||
}
|
||||
if (ds->audio_device)
|
||||
SDL_CloseAudioDevice(ds->audio_device);
|
||||
close_audio_device(ds->audio_device);
|
||||
ds->playing = false;
|
||||
}
|
||||
|
||||
|
@ -173,4 +152,4 @@ double ds_remainingtime(struct datastream *ds)
|
|||
double ds_length(struct datastream *ds)
|
||||
{
|
||||
return plm_get_duration(ds->plm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#ifndef DATASTREAM_H
|
||||
#define DATASTREAM_H
|
||||
|
||||
#include <SDL2/SDL_audio.h>
|
||||
|
||||
typedef struct plm_t plm_t;
|
||||
|
||||
#include <stdint.h>
|
||||
#include <pl_mpeg.h>
|
||||
|
||||
struct datastream {
|
||||
plm_t *plm;
|
||||
struct mShader *shader;
|
||||
double last_time;
|
||||
int playing;
|
||||
SDL_AudioDeviceID audio_device;
|
||||
int audio_device;
|
||||
uint32_t texture_y;
|
||||
uint32_t texture_cb;
|
||||
uint32_t texture_cr;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "engine.h"
|
||||
|
||||
#define PL_MPEG_IMPLEMENTATION
|
||||
#define CGLTF_IMPLEMENTATION
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#define STB_DS_IMPLEMENTATION
|
||||
|
@ -14,8 +13,8 @@
|
|||
#include <stb_image.h>
|
||||
#include <pl_mpeg.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include "render.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
#include "window.h"
|
||||
#include "camera.h"
|
||||
|
@ -26,51 +25,47 @@
|
|||
#include "registry.h"
|
||||
#include "log.h"
|
||||
#include "resources.h"
|
||||
#include "timer.h"
|
||||
#include "script.h"
|
||||
#include "vec.h"
|
||||
#include "sound.h"
|
||||
|
||||
// TODO: Init on the heap
|
||||
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
void error_callback(int error, const char *description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
void engine_init()
|
||||
{
|
||||
|
||||
|
||||
//Initialize SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR,
|
||||
"SDL could not initialize! SDL Error: %s", SDL_GetError());
|
||||
/* Initialize GLFW */
|
||||
if (!glfwInit()) {
|
||||
printf("Could not init GLFW\n");
|
||||
}
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
//Use OpenGL 3.3
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); /* How many x MSAA */
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
|
||||
|
||||
resources_init();
|
||||
script_init();
|
||||
registry_init();
|
||||
init_gameobjects();
|
||||
timer_init();
|
||||
|
||||
prefabs = vec_make(MAXNAME, 25);
|
||||
stbi_set_flip_vertically_on_load(1);
|
||||
phys2d_init();
|
||||
gui_init();
|
||||
sound_init();
|
||||
|
||||
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
|
||||
}
|
||||
|
||||
void engine_stop()
|
||||
{
|
||||
SDL_StopTextInput();
|
||||
SDL_Quit();
|
||||
}
|
||||
glfwTerminate();
|
||||
}
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
|
||||
#define FPS30 33
|
||||
#define FPS60 17
|
||||
#define FPS120 8;
|
||||
#define FPS120 8
|
||||
#define FPS144 7
|
||||
#define FPS300 3
|
||||
|
||||
#define sFPS30 0.033
|
||||
#define sFPS60 0.017
|
||||
#define sFPS120 0.008
|
||||
#define sFPS144 0.007
|
||||
#define sFPS300 0.003
|
||||
|
||||
void engine_init();
|
||||
void engine_stop();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "font.h"
|
||||
|
||||
#include "render.h"
|
||||
#include <shader.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
|
@ -33,7 +33,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
snprintf(fontpath, 256, "fonts/%s", fontfile);
|
||||
|
||||
stbtt_fontinfo fontinfo = { 0 };
|
||||
int i, j, ascent, baseline, ch = 0;
|
||||
int ascent = 0;
|
||||
|
||||
stbtt_InitFont(&fontinfo, ttf_buffer, 0);
|
||||
stbtt_GetFontVMetrics(&fontinfo, &ascent, 0, 0);
|
||||
|
@ -164,10 +164,6 @@ void text_settype(struct sFont *mfont)
|
|||
font = mfont;
|
||||
}
|
||||
|
||||
void strwidth(const char *str) {
|
||||
|
||||
}
|
||||
|
||||
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw)
|
||||
{
|
||||
shader_use(shader);
|
||||
|
@ -181,8 +177,8 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
|||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
char *line, *wordstart;
|
||||
line = text;
|
||||
const unsigned char *line, *wordstart;
|
||||
line = (unsigned char*)text;
|
||||
|
||||
|
||||
while (*line != '\0') {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include "resources.h"
|
||||
|
||||
struct vec *gameobjects = NULL;
|
||||
struct mGameObject *updateGO = NULL;
|
||||
|
@ -186,7 +187,7 @@ void gameobject_update(struct mGameObject *go)
|
|||
script_run(updateGO->update);
|
||||
}
|
||||
|
||||
vec_walk(go->components, component_update);
|
||||
vec_walk(go->components, &component_update);
|
||||
}
|
||||
|
||||
void gameobject_move(struct mGameObject *go, float xs, float ys)
|
||||
|
@ -205,5 +206,5 @@ void gameobject_rotate(struct mGameObject *go, float as)
|
|||
}
|
||||
|
||||
void update_gameobjects() {
|
||||
vec_walk(gameobjects, gameobject_update);
|
||||
}
|
||||
vec_walk(gameobjects, &gameobject_update);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
#ifndef GIZMO_H
|
||||
#define GIZMO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct gizmo {
|
||||
uint8_t color[3];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +1,35 @@
|
|||
#include "input.h"
|
||||
|
||||
#include "window.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int32_t mouseWheelX = 0;
|
||||
int32_t mouseWheelY = 0;
|
||||
int ychange = 0;
|
||||
int xchange = 0;
|
||||
float deltaT = 0;
|
||||
int quit = 0;
|
||||
SDL_Event e = { 0 };
|
||||
|
||||
uint8_t *currentKeystates = NULL;
|
||||
static double c_xpos;
|
||||
static double c_ypos;
|
||||
|
||||
static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
|
||||
{
|
||||
xchange = (int)xpos - c_xpos;
|
||||
ychange = (int)ypos - c_ypos;
|
||||
|
||||
c_xpos = xpos;
|
||||
c_ypos = ypos;
|
||||
}
|
||||
|
||||
static void scroll_cb(GLFWwindow *w, double xoffset, double yoffset)
|
||||
{
|
||||
mouseWheelY = yoffset;
|
||||
mouseWheelX = xoffset;
|
||||
}
|
||||
|
||||
void input_init()
|
||||
{
|
||||
glfwSetCursorPosCallback(mainwin->window, cursor_pos_cb);
|
||||
glfwSetScrollCallback(mainwin->window, scroll_cb);
|
||||
}
|
||||
|
||||
void input_poll()
|
||||
{
|
||||
|
@ -19,15 +37,25 @@ void input_poll()
|
|||
xchange = 0;
|
||||
mouseWheelX = 0;
|
||||
mouseWheelY = 0;
|
||||
currentKeystates = SDL_GetKeyboardState(NULL);
|
||||
|
||||
while (SDL_PollEvent(&e)) {
|
||||
window_all_handle_events(&e);
|
||||
glfwPollEvents();
|
||||
|
||||
#ifdef EDITOR
|
||||
//editor_input(&e);
|
||||
#endif
|
||||
}
|
||||
|
||||
//editor_input(&e);
|
||||
|
||||
}
|
||||
|
||||
void cursor_hide()
|
||||
{
|
||||
glfwSetInputMode(mainwin->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
|
||||
void cursor_show()
|
||||
{
|
||||
glfwSetInputMode(mainwin->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
int action_down(int scancode)
|
||||
{
|
||||
return glfwGetKey(mainwin->window, scancode);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdint.h>
|
||||
#include "window.h"
|
||||
|
||||
extern int32_t mouseWheelX;
|
||||
extern int32_t mouseWheelY;
|
||||
|
@ -10,9 +10,19 @@ extern int ychange;
|
|||
extern int xchange;
|
||||
extern float deltaT;
|
||||
extern int quit;
|
||||
extern SDL_Event e;
|
||||
extern uint8_t *currentKeystates;
|
||||
|
||||
void input_init();
|
||||
void input_poll();
|
||||
|
||||
void cursor_hide();
|
||||
void cursor_show();
|
||||
|
||||
int action_down(int scancode);
|
||||
|
||||
struct inputaction
|
||||
{
|
||||
int scancode;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
#include "vec.h"
|
||||
#include "gameobject.h"
|
||||
#include "resources.h"
|
||||
|
||||
void save_level(char name[MAXNAME])
|
||||
{
|
||||
|
|
|
@ -157,4 +157,4 @@ void spotlight_prepshader(struct mSpotLight *light, struct mShader *shader,
|
|||
shader_setfloat(shader, "spotLight.constant", light->constant);
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
|
||||
/*
|
||||
#include <stdint.h>
|
||||
|
||||
struct mLight {
|
||||
struct mGameObject obj;
|
||||
mfloat_t color[3];
|
||||
struct mGameObject *go;
|
||||
uint8_t color[3];
|
||||
float strength;
|
||||
int dynamic;
|
||||
int on;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
struct mPointLight {
|
||||
struct mLight light;
|
||||
float constant;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "log.h"
|
||||
|
||||
#include "render.h"
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#define logLevel 4
|
||||
|
||||
void mYughLog(int category, int priority, const char *message,
|
||||
int line, const char *file, ...)
|
||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||
{
|
||||
if (priority >= logLevel) {
|
||||
time_t now = time(0);
|
||||
|
@ -27,8 +26,7 @@ void mYughLog(int category, int priority, const char *message,
|
|||
snprintf(buffer, ERROR_BUFFER, "LEVEL %d :: %s [ %s:%d ] %s\n",
|
||||
priority, msgbuffer, file, line, dt);
|
||||
|
||||
//SDL_LogMessage(category, priority, buffer);
|
||||
printf(buffer);
|
||||
printf("%s", buffer);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
@ -38,19 +36,8 @@ void FlushGLErrors()
|
|||
GLenum glErr = GL_NO_ERROR;
|
||||
glErr = glGetError();
|
||||
while (glErr != GL_NO_ERROR) {
|
||||
YughLog(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_ERROR,
|
||||
YughLog(0, 3,
|
||||
"GL Error: %d", glErr);
|
||||
glErr = glGetError();
|
||||
}
|
||||
}
|
||||
|
||||
int TestSDLError(int sdlErr)
|
||||
{
|
||||
if (sdlErr != 0) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR, "SDL Error :: %s",
|
||||
SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -1,17 +1,19 @@
|
|||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
|
||||
#include <SDL2/SDL_log.h>
|
||||
|
||||
#define ERROR_BUFFER 2048
|
||||
|
||||
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, msg, __LINE__, __FILE__, __VA_ARGS__)
|
||||
#define LOG_INFO 0
|
||||
#define LOG_WARN 1
|
||||
#define LOG_ERROR 2
|
||||
#define LOG_CRITICAL 3
|
||||
|
||||
void mYughLog(int category, int priority, const char *message,
|
||||
int line, const char *file, ...);
|
||||
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__)
|
||||
|
||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...);
|
||||
|
||||
void FlushGLErrors();
|
||||
|
||||
int TestSDLError(int sdlErr);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -44,8 +44,6 @@ const mint_t VEC3I_ONE[3] = { 1, 1, 1 };
|
|||
|
||||
#include <string.h>
|
||||
|
||||
typedef float mfloat_t;
|
||||
|
||||
#if defined(MATHC_USE_INT)
|
||||
mint_t clampi(mint_t value, mint_t min, mint_t max)
|
||||
{
|
||||
|
@ -4971,9 +4969,10 @@ bool squat_is_equal(struct quat q0, struct quat q1)
|
|||
return quat_is_equal((mfloat_t *) & q0, (mfloat_t *) & q1);
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
struct quat squat_from_euler(mfloat_t x, mfloat_t y, mfloat_t z)
|
||||
{
|
||||
struct quat result;
|
||||
struct quat result = {0};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "mesh.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "shader.h"
|
||||
#include "texture.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
void DrawMesh(struct mMesh *mesh, struct mShader *shader)
|
||||
{
|
||||
|
@ -18,26 +18,26 @@ void DrawMesh(struct mMesh *mesh, struct mShader *shader)
|
|||
for (uint32_t i = 0; i < (mesh->te - mesh->textures); i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i); // active proper texture unit before binding
|
||||
// retrieve texture number (the N in diffuse_textureN)
|
||||
char number;
|
||||
char number = 0;
|
||||
// TODO: malloc every single frame ... nope! Change to stack
|
||||
char *name =
|
||||
/*char *name =
|
||||
(char *) malloc(sizeof(char) *
|
||||
(strlen(mesh->textures[i].type) + 2));
|
||||
if (mesh->textures[i].type == "texture_diffuse")
|
||||
(strlen(mesh->textures[i].type) + 2));*/
|
||||
if (mesh->textures[i].type == TEX_DIFF)
|
||||
number = diffuseNr++;
|
||||
else if (mesh->textures[i].type == "texture_specular")
|
||||
else if (mesh->textures[i].type == TEX_SPEC)
|
||||
number = specularNr++;
|
||||
else if (mesh->textures[i].type == "texture_normal")
|
||||
else if (mesh->textures[i].type == TEX_NORM)
|
||||
number = normalNr++;
|
||||
else if (mesh->textures[i].type == "texture_height")
|
||||
else if (mesh->textures[i].type == TEX_HEIGHT)
|
||||
number = heightNr++;
|
||||
|
||||
sprintf(name, "%s%d", mesh->textures[i].type, number);
|
||||
// now set the sampler to the correct texture unit
|
||||
|
||||
/*
|
||||
glUniform1i(glGetUniformLocation(shader->id, name), i);
|
||||
// and finally bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, mesh->textures[i].id);
|
||||
free(name);
|
||||
*/
|
||||
}
|
||||
|
||||
// draw mesh
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shader.h"
|
||||
#include <cgltf.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct mModel *lastRendered;
|
||||
static struct mModel *loadedModels[100];
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "openglrender.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
#include "shader.h"
|
||||
#include "font.h"
|
||||
|
@ -15,7 +14,7 @@
|
|||
int renderMode = 0;
|
||||
|
||||
static GLuint UBO;
|
||||
static GLuint UBOBind = 0;
|
||||
|
||||
|
||||
static GLuint gridVBO = 0;
|
||||
static GLuint gridVAO = 0;
|
||||
|
@ -84,22 +83,17 @@ bool renderReflection = true;
|
|||
struct mGameObject *selectedobject = NULL;
|
||||
char objectName[200] = { '\0' }; // object name buffer
|
||||
|
||||
uint16_t debugColorPickBO = 0;
|
||||
uint16_t debugColorPickTEX = 0;
|
||||
GLuint debugColorPickBO = 0;
|
||||
GLuint debugColorPickTEX = 0;
|
||||
|
||||
|
||||
struct mSprite *tsprite = NULL;
|
||||
static struct mSprite *tanim = NULL;
|
||||
|
||||
|
||||
static unsigned int projUBO;
|
||||
|
||||
void openglInit()
|
||||
{
|
||||
if (SDL_GL_SetSwapInterval(1)) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_WARN,
|
||||
"Unable to set VSync! SDL Error: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
sprite_initialize();
|
||||
|
||||
////// MAKE SHADERS
|
||||
|
@ -222,34 +216,7 @@ void openglRender(struct mSDLWindow *window, struct mCamera *mcamera)
|
|||
|
||||
void openglInit3d(struct mSDLWindow *window)
|
||||
{
|
||||
//Initialize SDL
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR,
|
||||
"SDL could not initialize! SDL Error: %s", SDL_GetError());
|
||||
}
|
||||
//Use OpenGL 3.3
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); /* How many x MSAA */
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
|
||||
|
||||
// TODO: Add non starter initializtion return here for some reason?
|
||||
MakeSDLWindow("Untitled Game", 1280, 720,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
|
||||
|
||||
//Use Vsync
|
||||
if (!SDL_GL_SetSwapInterval(1)) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_WARN,
|
||||
"Unable to set VSync! SDL Error: %s", SDL_GetError());
|
||||
}
|
||||
/* TODO: IMG init doesn't work in C+
|
||||
/* TODO: IMG init doesn't work in C++
|
||||
int init =(0x00000001 | 0x00000002);
|
||||
int initted =IMG_Init(init);
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR, "Init flags: %d\nInitted values: %d ", init, initted);
|
||||
|
@ -438,7 +405,7 @@ void openglRender3d(struct mSDLWindow *window, struct mCamera *mcamera)
|
|||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Configure matrices with an orthogonal
|
||||
mfloat_t lightView[16] = { 0.f };
|
||||
|
||||
mfloat_t lightSpaceMatrix[16] = { 0.f };
|
||||
|
||||
/*
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define OPENGL_RENDER_H
|
||||
|
||||
#include "render.h"
|
||||
#include "window.h"
|
||||
|
||||
struct mCamera;
|
||||
struct mSDLWindow;
|
||||
|
@ -31,7 +30,7 @@ extern float plane_size;
|
|||
extern float near_plane;
|
||||
extern float far_plane;
|
||||
extern char objectName[];
|
||||
extern uint16_t debugColorPickBO;
|
||||
extern GLuint debugColorPickBO;
|
||||
|
||||
extern struct mGameObject *selectedobject;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ int ncomponent = 0;
|
|||
void registry_init()
|
||||
{
|
||||
register_component("Sprite", sizeof(struct mSprite), &MakeSprite, NULL,
|
||||
sprite_gui, &sprite_init, NULL);
|
||||
&sprite_gui, &sprite_init, NULL);
|
||||
register_component("2D Circle Collider", sizeof(struct phys2d_circle),
|
||||
&Make2DCircle, &phys2d_dbgdrawcircle, &circle_gui,
|
||||
&phys2d_circleinit, NULL);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#ifndef RENDER_H
|
||||
#define RENDER_H
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/glew.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *DATA_PATH = NULL;
|
||||
char *PREF_PATH = NULL;
|
||||
|
@ -22,7 +23,6 @@ const char *EXT_LEVEL = ".level";
|
|||
int stemlen = 0;
|
||||
|
||||
static const char *cur_ext = NULL;
|
||||
static DIR *cur_dir = NULL;
|
||||
struct dirent *c_dirent = NULL;
|
||||
struct vec *c_vec = NULL;
|
||||
|
||||
|
@ -35,9 +35,6 @@ void resources_init()
|
|||
getcwd(DATA_PATH, 256);
|
||||
strncat(DATA_PATH, "/", 256);
|
||||
|
||||
|
||||
|
||||
PREF_PATH = SDL_GetPrefPath("Odplot", "Test Game");
|
||||
if (!PREF_PATH)
|
||||
PREF_PATH = strdup("./tmp/");
|
||||
}
|
||||
|
@ -104,7 +101,7 @@ void findPrefabs()
|
|||
fill_extensions(prefabs, DATA_PATH, EXT_PREFAB);
|
||||
}
|
||||
|
||||
FILE *path_open(const char *fmt, const char *tag, ...)
|
||||
FILE *path_open(const char *tag, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
@ -115,9 +112,9 @@ FILE *path_open(const char *fmt, const char *tag, ...)
|
|||
return f;
|
||||
}
|
||||
|
||||
char *make_path(char *file)
|
||||
char *make_path(const char *file)
|
||||
{
|
||||
strncpy(pathbuf, DATA_PATH, MAXPATH);
|
||||
strncat(pathbuf, file, MAXPATH);
|
||||
return pathbuf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ void fill_extensions(struct vec *vec, const char *path, const char *ext);
|
|||
char *get_filename_from_path(char *path, int extension);
|
||||
char *get_directory_from_path(char *path);
|
||||
FILE *res_open(char *path, const char *tag);
|
||||
FILE *path_open(const char *fmt, const char *tag, ...);
|
||||
char *make_path(char *file);
|
||||
FILE *path_open(const char *tag, const char *fmt, ...);
|
||||
char *make_path(const char *file);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,4 +51,4 @@ void script_init()
|
|||
void script_run(const char *script)
|
||||
{
|
||||
s7_eval_c_string(s7, script);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,4 @@ extern struct s7_scheme *s7;
|
|||
void script_init();
|
||||
void script_run(const char *script);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "shader.h"
|
||||
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include "resources.h"
|
||||
#include <GL/glew.h>
|
||||
|
||||
#define SHADER_BUF 10000
|
||||
|
||||
|
@ -33,7 +33,7 @@ int shader_compile_error(GLuint shader)
|
|||
if (success) return 0;
|
||||
|
||||
glGetShaderInfoLog(shader, ERROR_BUFFER, NULL, infoLog);
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR, "Shader compilation error.\nLog: %s", infoLog);
|
||||
YughLog(0, LOG_ERROR, "Shader compilation error.\nLog: %s", infoLog);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ int shader_link_error(GLuint shader)
|
|||
if (success) return 0;
|
||||
|
||||
glGetProgramInfoLog(shader, ERROR_BUFFER, NULL, infoLog);
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR, "Shader link error.\nLog: %s", infoLog);
|
||||
YughLog(0, LOG_ERROR, "Shader link error.\nLog: %s", infoLog);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
GLuint load_shader_from_file(char *path, int type)
|
||||
GLuint load_shader_from_file(const char *path, int type)
|
||||
{
|
||||
char spath[MAXPATH] = {'\0'};
|
||||
|
||||
|
@ -169,7 +169,7 @@ void shader_compile_all()
|
|||
{
|
||||
struct mShader **curshader = mshaders;
|
||||
do {
|
||||
YughLog(0, SDL_LOG_PRIORITY_INFO, "Compiled Shader %d", 1);
|
||||
YughLog(0, LOG_INFO, "Compiled Shader %d", 1);
|
||||
shader_compile(*curshader);
|
||||
} while (++curshader != lastShader);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "shader.h"
|
||||
#include "camera.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
|
@ -71,24 +72,27 @@ struct mSkybox *MakeSkybox(const char *cubemap)
|
|||
shader_use(newskybox->shader);
|
||||
shader_setint(newskybox->shader, "skybox", 0);
|
||||
|
||||
/*
|
||||
const char *faces[6] =
|
||||
{ "right.jpg", "left.jpg", "top.jpg", "bottom.jpg", "front.jpg",
|
||||
"back.jpg"
|
||||
};
|
||||
*/
|
||||
|
||||
glGenTextures(1, &newskybox->id);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, newskybox->id);
|
||||
char buf[100] = { '\0' };
|
||||
/*char buf[100] = { '\0' };*/
|
||||
|
||||
for (unsigned int i = 0; i < 6; i++) {
|
||||
/*
|
||||
buf[0] = '\0';
|
||||
strcat(buf, cubemap);
|
||||
strcat(buf, "/");
|
||||
strcat(buf, faces[i]);
|
||||
SDL_Surface *data = NULL; //IMG_Load(buf);
|
||||
IMG_Load(buf);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 2048,
|
||||
2048, 0, GL_RGB, GL_UNSIGNED_BYTE, data->pixels);
|
||||
SDL_FreeSurface(data);
|
||||
*/
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "sound.h"
|
||||
#include "resources.h"
|
||||
|
||||
const char *audioDriver;
|
||||
|
||||
|
@ -8,11 +9,13 @@ void sound_init()
|
|||
{
|
||||
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
|
||||
int err = Mix_Init(flags);
|
||||
if (err&flags != flags) {
|
||||
if ((err&flags) != flags) {
|
||||
printf("MIX did not init!!");
|
||||
}
|
||||
|
||||
mus_ch = Mix_AllocateChannels(1);
|
||||
|
||||
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
|
||||
}
|
||||
|
||||
void audio_open(const char *device)
|
||||
|
@ -91,4 +94,32 @@ void music_stop()
|
|||
void audio_init()
|
||||
{
|
||||
audioDriver = SDL_GetAudioDeviceName(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void play_raw(int device, void *data, int size)
|
||||
{
|
||||
SDL_QueueAudio(device, data, size);
|
||||
}
|
||||
|
||||
void close_audio_device(int device)
|
||||
{
|
||||
SDL_CloseAudioDevice(device);
|
||||
}
|
||||
|
||||
void clear_raw(int device)
|
||||
{
|
||||
SDL_ClearQueuedAudio(device);
|
||||
}
|
||||
|
||||
int open_device(const char *adriver)
|
||||
{
|
||||
SDL_AudioSpec audio_spec;
|
||||
SDL_memset(&audio_spec, 0, sizeof(audio_spec));
|
||||
audio_spec.freq = 48000;
|
||||
audio_spec.format = AUDIO_F32;
|
||||
audio_spec.channels = 2;
|
||||
audio_spec.samples = 4096;
|
||||
int dev = (int) SDL_OpenAudioDevice(adriver, 0, &audio_spec, NULL, 0);
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
return dev;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
|
||||
|
||||
struct sound {
|
||||
Mix_Chunk *sound;
|
||||
unsigned char volume;
|
||||
|
@ -15,10 +13,6 @@ struct music {
|
|||
unsigned char volume;
|
||||
};
|
||||
|
||||
struct player {
|
||||
|
||||
};
|
||||
|
||||
extern const char *audioDriver;
|
||||
|
||||
void sound_init();
|
||||
|
@ -41,6 +35,11 @@ void music_resume();
|
|||
void music_pause();
|
||||
void music_stop();
|
||||
|
||||
void close_audio_device(int device);
|
||||
void clear_raw(int device);
|
||||
void play_raw(int device, void *data, int size);
|
||||
int open_device(const char *adriver);
|
||||
|
||||
void audio_init();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "sprite.h"
|
||||
|
||||
|
||||
#include "timer.h"
|
||||
#include "render.h"
|
||||
#include "openglrender.h"
|
||||
#include "texture.h"
|
||||
|
@ -18,14 +19,13 @@ static struct mShader *spriteShader = NULL;
|
|||
static struct mShader *animSpriteShader = NULL;
|
||||
*/
|
||||
|
||||
struct TextureOptions TEX_SPRITE = { 1, 0 };
|
||||
struct TextureOptions TEX_SPRITE = { 1, 0, 0 };
|
||||
|
||||
struct mSprite *sprites[100] = { NULL };
|
||||
|
||||
int numSprites = 0;
|
||||
|
||||
static uint32_t quadVAO;
|
||||
static uint32_t VBO;
|
||||
|
||||
struct mSprite *MakeSprite(struct mGameObject *go)
|
||||
{
|
||||
|
@ -58,8 +58,7 @@ void sprite_loadanim(struct mSprite *sprite, const char *path,
|
|||
{
|
||||
sprite->tex = texture_loadfromfile(path);
|
||||
sprite->anim = anim;
|
||||
sprite->anim.timer =
|
||||
SDL_AddTimer(sprite->anim.ms, incrementAnimFrame, sprite);
|
||||
sprite->anim.timer = timer_make(sprite->anim.ms, &incrementAnimFrame, sprite);
|
||||
/*
|
||||
sprite->tex = texture_loadanimfromfile(sprite->tex, path, sprite->anim.frames,
|
||||
sprite->anim.dimensions);
|
||||
|
@ -71,7 +70,7 @@ void sprite_settex(struct mSprite *sprite, struct Texture *tex)
|
|||
sprite->tex = tex;
|
||||
}
|
||||
|
||||
Uint32 incrementAnimFrame(Uint32 interval, struct mSprite *sprite)
|
||||
unsigned int incrementAnimFrame(unsigned int interval, struct mSprite *sprite)
|
||||
{
|
||||
sprite->anim.frame = (sprite->anim.frame + 1) % sprite->anim.frames;
|
||||
return interval;
|
||||
|
@ -220,4 +219,4 @@ struct mSprite *gui_makesprite()
|
|||
{
|
||||
struct mSprite *new = MakeSprite(gui_go);
|
||||
return new;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include "timer.h"
|
||||
#include "mathc.h"
|
||||
|
||||
struct datastream;
|
||||
struct mGameObject;
|
||||
struct Texture;
|
||||
|
||||
struct timer;
|
||||
|
||||
struct Anim2D {
|
||||
int frames;
|
||||
int frame;
|
||||
int dimensions[2];
|
||||
SDL_TimerID timer;
|
||||
struct timer *timer;
|
||||
int ms;
|
||||
};
|
||||
|
||||
|
@ -36,12 +38,12 @@ void sprite_loadtex(struct mSprite *sprite, const char *path);
|
|||
void sprite_loadanim(struct mSprite *sprite, const char *path,
|
||||
struct Anim2D anim);
|
||||
void sprite_settex(struct mSprite *sprite, struct Texture *tex);
|
||||
void sprite_initalize();
|
||||
void sprite_initialize();
|
||||
void sprite_draw(struct mSprite *sprite);
|
||||
void spriteanim_draw(struct mSprite *sprite);
|
||||
void video_draw(struct datastream *ds, mfloat_t pos[2], mfloat_t size[2],
|
||||
float rotate, mfloat_t color[3]);
|
||||
Uint32 incrementAnimFrame(Uint32 interval, struct mSprite *sprite);
|
||||
unsigned int incrementAnimFrame(unsigned int interval, struct mSprite *sprite);
|
||||
|
||||
struct mSprite *gui_makesprite();
|
||||
void gui_init();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "texture.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "render.h"
|
||||
#include <stdio.h>
|
||||
#include <stb_image.h>
|
||||
#include <stb_ds.h>
|
||||
#include <GL/glew.h>
|
||||
#include "log.h"
|
||||
#include <math.h>
|
||||
|
||||
static struct {
|
||||
char *key;
|
||||
|
@ -59,7 +59,7 @@ struct Texture *texture_loadfromfile(const char *path)
|
|||
|
||||
void tex_pull(struct Texture *tex)
|
||||
{
|
||||
uint8_t n;
|
||||
int n;
|
||||
stbi_set_flip_vertically_on_load(0);
|
||||
tex->data = stbi_load(tex->path, &tex->width, &tex->height, &n, 4);
|
||||
|
||||
|
@ -112,6 +112,7 @@ void tex_gpu_load(struct Texture *tex)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
} else {
|
||||
/*
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex->id);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
0,
|
||||
|
@ -163,10 +164,11 @@ void tex_gpu_load(struct Texture *tex)
|
|||
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
SDL_FreeSurface(tempSurface);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 tex_incr_anim(Uint32 interval, struct TexAnimation *tex_anim)
|
||||
unsigned int tex_incr_anim(unsigned int interval, struct TexAnimation *tex_anim)
|
||||
{
|
||||
anim_incr(tex_anim);
|
||||
|
||||
|
@ -195,9 +197,9 @@ void anim_decr(struct TexAnimation *anim)
|
|||
void tex_anim_set(struct TexAnimation *anim)
|
||||
{
|
||||
if (anim->playing) {
|
||||
SDL_RemoveTimer(anim->timer);
|
||||
timer_remove(anim->timer);
|
||||
anim->timer =
|
||||
SDL_AddTimer(floor(1000.f / anim->tex->anim.ms), tex_incr_anim,
|
||||
timer_make(floor(1000.f / anim->tex->anim.ms), &tex_incr_anim,
|
||||
anim);
|
||||
|
||||
}
|
||||
|
@ -262,9 +264,9 @@ void anim_play(struct TexAnimation *anim)
|
|||
anim->frame = 0;
|
||||
|
||||
anim->playing = 1;
|
||||
SDL_RemoveTimer(anim->timer);
|
||||
timer_remove(anim->timer);
|
||||
anim->timer =
|
||||
SDL_AddTimer(floor(1000.f / anim->tex->anim.ms), tex_incr_anim,
|
||||
timer_make(floor(1000.f / anim->tex->anim.ms), &tex_incr_anim,
|
||||
anim);
|
||||
}
|
||||
|
||||
|
@ -276,7 +278,7 @@ void anim_stop(struct TexAnimation *anim)
|
|||
anim->playing = 0;
|
||||
anim->frame = 0;
|
||||
anim->pausetime = 0;
|
||||
SDL_RemoveTimer(anim->timer);
|
||||
timer_remove(anim->timer);
|
||||
tex_anim_calc_uv(anim);
|
||||
}
|
||||
|
||||
|
@ -286,7 +288,7 @@ void anim_pause(struct TexAnimation *anim)
|
|||
return;
|
||||
|
||||
anim->playing = 0;
|
||||
SDL_RemoveTimer(anim->timer);
|
||||
timer_remove(anim->timer);
|
||||
}
|
||||
|
||||
void anim_fwd(struct TexAnimation *anim)
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include "timer.h"
|
||||
|
||||
#define TEX_SPEC 0
|
||||
#define TEX_NORM 1
|
||||
#define TEX_HEIGHT 2
|
||||
#define TEX_DIFF 3
|
||||
|
||||
|
||||
struct Rect {
|
||||
float x;
|
||||
|
@ -14,7 +20,7 @@ struct TexAnimation {
|
|||
int frame;
|
||||
int playing;
|
||||
int pausetime;
|
||||
SDL_TimerID timer;
|
||||
struct timer *timer;
|
||||
struct Rect uv;
|
||||
struct Texture *tex;
|
||||
};
|
||||
|
@ -33,7 +39,7 @@ struct TextureOptions {
|
|||
};
|
||||
|
||||
struct Texture {
|
||||
char *type;
|
||||
int type;
|
||||
unsigned int id;
|
||||
char *path;
|
||||
int width;
|
||||
|
@ -65,7 +71,7 @@ void anim_bkwd(struct TexAnimation *anim);
|
|||
void anim_incr(struct TexAnimation *anim);
|
||||
void anim_decr(struct TexAnimation *anim);
|
||||
|
||||
Uint32 tex_incr_anim(Uint32 interval, struct TexAnimation *tex_anim);
|
||||
unsigned int tex_incr_anim(unsigned int interval, struct TexAnimation *tex_anim);
|
||||
void tex_anim_calc_uv(struct TexAnimation *anim);
|
||||
void tex_anim_set(struct TexAnimation *anim);
|
||||
|
||||
|
|
25
source/engine/thirdparty/enet/src/win32.c
vendored
25
source/engine/thirdparty/enet/src/win32.c
vendored
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/**
|
||||
@file win32.c
|
||||
@brief ENet Win32 system specific functions
|
||||
*/
|
||||
|
@ -16,7 +16,7 @@ enet_initialize (void)
|
|||
{
|
||||
WORD versionRequested = MAKEWORD (1, 1);
|
||||
WSADATA wsaData;
|
||||
|
||||
|
||||
if (WSAStartup (versionRequested, & wsaData))
|
||||
return -1;
|
||||
|
||||
|
@ -24,7 +24,7 @@ enet_initialize (void)
|
|||
HIBYTE (wsaData.wVersion) != 1)
|
||||
{
|
||||
WSACleanup ();
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -121,9 +121,9 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
|
|||
{
|
||||
struct in_addr in;
|
||||
struct hostent * hostEntry;
|
||||
|
||||
|
||||
in.s_addr = address -> host;
|
||||
|
||||
|
||||
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
|
||||
if (hostEntry == NULL)
|
||||
return enet_address_get_host_ip (address, name, nameLength);
|
||||
|
@ -280,8 +280,8 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
|||
struct sockaddr_in sin;
|
||||
int sinLength = sizeof (struct sockaddr_in);
|
||||
|
||||
result = accept (socket,
|
||||
address != NULL ? (struct sockaddr *) & sin : NULL,
|
||||
result = accept (socket,
|
||||
address != NULL ? (struct sockaddr *) & sin : NULL,
|
||||
address != NULL ? & sinLength : NULL);
|
||||
|
||||
if (result == INVALID_SOCKET)
|
||||
|
@ -327,7 +327,7 @@ enet_socket_send (ENetSocket socket,
|
|||
sin.sin_addr.s_addr = address -> host;
|
||||
}
|
||||
|
||||
if (WSASendTo (socket,
|
||||
if (WSASendTo (socket,
|
||||
(LPWSABUF) buffers,
|
||||
(DWORD) bufferCount,
|
||||
& sentLength,
|
||||
|
@ -406,10 +406,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
|||
fd_set readSet, writeSet;
|
||||
struct timeval timeVal;
|
||||
int selectCount;
|
||||
|
||||
|
||||
timeVal.tv_sec = timeout / 1000;
|
||||
timeVal.tv_usec = (timeout % 1000) * 1000;
|
||||
|
||||
|
||||
FD_ZERO (& readSet);
|
||||
FD_ZERO (& writeSet);
|
||||
|
||||
|
@ -431,12 +431,11 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
|||
|
||||
if (FD_ISSET (socket, & writeSet))
|
||||
* condition |= ENET_SOCKET_WAIT_SEND;
|
||||
|
||||
|
||||
if (FD_ISSET (socket, & readSet))
|
||||
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
3710
source/engine/thirdparty/pl_mpeg/include/pl_mpeg.h
vendored
3710
source/engine/thirdparty/pl_mpeg/include/pl_mpeg.h
vendored
File diff suppressed because it is too large
Load diff
|
@ -35,12 +35,6 @@
|
|||
// // TODO: Figure out how to translate rotation to a global rotation
|
||||
// }
|
||||
|
||||
mfloat_t *follow_calcpos()
|
||||
{
|
||||
mfloat_t p1[3] = { 0 };
|
||||
mfloat_t p2[3] = { 0 };
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
glm::vec3 ThirdPersonFollow::CalculatePosition()
|
||||
|
|
|
@ -10,7 +10,6 @@ struct follow {
|
|||
mfloat_t target_rot[4];
|
||||
};
|
||||
|
||||
mfloat_t *follow_calcpos();
|
||||
mfloat_t *follow_calccenter();
|
||||
mfloat_t *follow_postoffset();
|
||||
mfloat_t *extentsoffset();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "vec.h"
|
||||
#include "log.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
struct vec *vec_make(int width, int size)
|
||||
struct vec *vec_make(size_t width, int size)
|
||||
{
|
||||
struct vec *new = calloc(1, sizeof(struct vec));
|
||||
new->size = size;
|
||||
|
@ -25,7 +26,7 @@ void *vec_get(struct vec *vec, int n)
|
|||
void vec_walk(struct vec *vec, void (*fn)(void *data))
|
||||
{
|
||||
for(int i = 0; i < vec->len; i++)
|
||||
fn((char *) (vec->data + (i * vec->width)));
|
||||
fn((char*)vec->data + (i * vec->width));
|
||||
}
|
||||
|
||||
void vec_delete(struct vec *vec, int n)
|
||||
|
@ -46,7 +47,7 @@ void vec_del_order(struct vec *vec, int n)
|
|||
}
|
||||
}
|
||||
|
||||
void *vec_add(struct vec *vec, void *data)
|
||||
void *vec_add(struct vec *vec, const void *data)
|
||||
{
|
||||
if (vec->size == vec->len)
|
||||
vec_expand(vec);
|
||||
|
@ -70,7 +71,7 @@ void *vec_add_sort(struct vec *vec, void *data,
|
|||
while (sort(vec_p(vec, n), data))
|
||||
n--;
|
||||
|
||||
vec_insert(vec, data, n);
|
||||
return vec_insert(vec, data, n);
|
||||
}
|
||||
|
||||
void *vec_insert(struct vec *vec, void *data, int n)
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
struct vec {
|
||||
int len;
|
||||
int size;
|
||||
int width;
|
||||
size_t width;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct vec *vec_make(int width, int size);
|
||||
struct vec *vec_make(size_t width, int size);
|
||||
void *vec_get(struct vec *vec, int n);
|
||||
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
||||
void vec_clear(struct vec *vec);
|
||||
void *vec_add(struct vec *vec, void *data);
|
||||
void *vec_add(struct vec *vec, const void *data);
|
||||
|
||||
/* sort returns 0 for a<=b, 1 for a>b */
|
||||
void *vec_add_sort(struct vec *vec, void *data,
|
||||
|
@ -29,4 +29,4 @@ char *vec_p(struct vec *vec, int n);
|
|||
void vec_expand(struct vec *vec);
|
||||
void vec_fit(struct vec *vec);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,62 +1,54 @@
|
|||
#include "window.h"
|
||||
|
||||
#include "openglrender.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "texture.h"
|
||||
#include "log.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct mSDLWindow *window = NULL;
|
||||
struct mSDLWindow *mainwin;
|
||||
|
||||
static struct mSDLWindow *windows[5];
|
||||
static int numWindows = 0;
|
||||
|
||||
static SDL_GLContext publicGLContext = NULL;
|
||||
|
||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||
uint32_t flags)
|
||||
{
|
||||
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
|
||||
w->width = width;
|
||||
w->height = height;
|
||||
w->window = SDL_CreateWindow(name, 0, 0, width, height, flags);
|
||||
w->window = glfwCreateWindow(width, height, "New Game", NULL, NULL);
|
||||
|
||||
if (w->window == NULL) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR,
|
||||
"Window could not be created! SDL Error: %s",
|
||||
SDL_GetError());
|
||||
if (!w->window) {
|
||||
printf("Couldn't make GLFW window\n");
|
||||
} else {
|
||||
if (publicGLContext == NULL) {
|
||||
publicGLContext = SDL_GL_CreateContext(w->window);
|
||||
}
|
||||
glfwMakeContextCurrent(w->window);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
w->glContext = publicGLContext;
|
||||
SDL_GL_MakeCurrent(w->window, w->glContext);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
w->id = numWindows;
|
||||
|
||||
if (publicGLContext == NULL) {
|
||||
YughLog(0, SDL_LOG_PRIORITY_ERROR,
|
||||
"OpenGL context could not be created! SDL Error: %s",
|
||||
SDL_GetError());
|
||||
}
|
||||
|
||||
w->id = SDL_GetWindowID(w->window);
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
glewInit();
|
||||
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
||||
if (numWindows < 5)
|
||||
windows[numWindows++] = w;
|
||||
|
||||
}
|
||||
|
||||
|
||||
mainwin = windows[0];
|
||||
return w;
|
||||
}
|
||||
|
||||
void window_handle_event(struct mSDLWindow *w, SDL_Event * e)
|
||||
void window_destroy(struct mSDLWindow *w)
|
||||
{
|
||||
glfwDestroyWindow(w->window);
|
||||
}
|
||||
|
||||
void window_handle_event(struct mSDLWindow *w)
|
||||
{
|
||||
/*
|
||||
if (e->type == SDL_WINDOWEVENT && e->window.windowID == w->id) { // TODO: Check ptr direct?
|
||||
switch (e->window.event) {
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
|
@ -77,9 +69,9 @@ void window_handle_event(struct mSDLWindow *w, SDL_Event * e)
|
|||
"Changed size of window %d: width %d, height %d.",
|
||||
w->id, w->width, w->height);
|
||||
window_makecurrent(w);
|
||||
/*w.projection =
|
||||
w.projection =
|
||||
glm::ortho(0.f, (float) width, 0.f, (float) height, -1.f,
|
||||
1.f); */
|
||||
1.f);
|
||||
w->render = true;
|
||||
break;
|
||||
|
||||
|
@ -134,18 +126,19 @@ void window_handle_event(struct mSDLWindow *w, SDL_Event * e)
|
|||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void window_all_handle_events(SDL_Event *e)
|
||||
void window_all_handle_events()
|
||||
{
|
||||
for (int i = 0; i < numWindows; i++) {
|
||||
window_handle_event(windows[i], e);
|
||||
window_handle_event(windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void window_makefullscreen(struct mSDLWindow *w)
|
||||
{
|
||||
SDL_SetWindowFullscreen(w->window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
glfwMaximizeWindow(w->window);
|
||||
w->fullscreen = true;
|
||||
}
|
||||
|
||||
|
@ -156,31 +149,48 @@ void window_togglefullscreen(struct mSDLWindow *w)
|
|||
if (w->fullscreen) {
|
||||
window_makefullscreen(w);
|
||||
} else {
|
||||
SDL_SetWindowFullscreen(w->window, 0);
|
||||
glfwRestoreWindow(w->window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void window_makecurrent(struct mSDLWindow *w)
|
||||
{
|
||||
/*
|
||||
if (w->window != SDL_GL_GetCurrentWindow())
|
||||
SDL_GL_MakeCurrent(w->window, w->glContext);
|
||||
glViewport(0, 0, w->width, w->height);
|
||||
*/
|
||||
}
|
||||
|
||||
void window_swap(struct mSDLWindow *w)
|
||||
{
|
||||
SDL_GL_SwapWindow(w->window);
|
||||
glfwSwapBuffers(w->window);
|
||||
}
|
||||
|
||||
void window_seticon(struct mSDLWindow *w, struct Texture *icon)
|
||||
{
|
||||
SDL_Surface *winIcon = SDL_CreateRGBSurfaceWithFormatFrom(icon->data, icon->width, icon->height, 32, 4*icon->width, SDL_PIXELFORMAT_RGBA32);
|
||||
SDL_SetWindowIcon(w->window, winIcon);
|
||||
SDL_FreeSurface(winIcon);
|
||||
/*
|
||||
GLFWimage images[1];
|
||||
images[0] = load_icon(icon->path);
|
||||
glfwSetWindowIcon(w->window, 1, images);
|
||||
*/
|
||||
}
|
||||
|
||||
int window_hasfocus(struct mSDLWindow *w)
|
||||
{
|
||||
return SDL_GetWindowFlags(w->window) & SDL_WINDOW_INPUT_FOCUS;
|
||||
}
|
||||
return glfwGetWindowAttrib(w->window, GLFW_FOCUSED);
|
||||
}
|
||||
|
||||
double frame_time()
|
||||
{
|
||||
return glfwGetTime();
|
||||
}
|
||||
|
||||
double elapsed_time()
|
||||
{
|
||||
static double last_time;
|
||||
static double elapsed;
|
||||
elapsed = frame_time() - last_time;
|
||||
return elapsed;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "render.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct mSDLWindow {
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glContext;
|
||||
GLFWwindow *window;
|
||||
int id;
|
||||
int width;
|
||||
int height;
|
||||
|
@ -22,10 +22,15 @@ struct mSDLWindow {
|
|||
|
||||
struct Texture;
|
||||
|
||||
extern struct mSDLWindow *mainwin;
|
||||
|
||||
|
||||
|
||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||
uint32_t flags);
|
||||
void window_handle_event(struct mSDLWindow *w, SDL_Event * e);
|
||||
void window_all_handle_events(SDL_Event *e);
|
||||
void window_destroy(struct mSDLWindow *w);
|
||||
void window_handle_event(struct mSDLWindow *w);
|
||||
void window_all_handle_events();
|
||||
void window_makecurrent(struct mSDLWindow *w);
|
||||
void window_makefullscreen(struct mSDLWindow *w);
|
||||
void window_togglefullscreen(struct mSDLWindow *w);
|
||||
|
@ -33,4 +38,7 @@ void window_swap(struct mSDLWindow *w);
|
|||
void window_seticon(struct mSDLWindow *w, struct Texture *icon);
|
||||
int window_hasfocus(struct mSDLWindow *w);
|
||||
|
||||
double frame_time();
|
||||
double elapsed_time();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include "render.h"
|
||||
#include "camera.h"
|
||||
#include "window.h"
|
||||
#include "engine.h"
|
||||
|
@ -10,14 +10,11 @@
|
|||
|
||||
int physOn = 0;
|
||||
unsigned int frameCount = 0;
|
||||
Uint32 lastTick = 0;
|
||||
Uint32 frameTick = 0;
|
||||
Uint32 elapsed = 0;
|
||||
|
||||
Uint32 physMS = FPS144;
|
||||
Uint32 physlag = 0;
|
||||
Uint32 renderMS = FPS144;
|
||||
Uint32 renderlag = 0;
|
||||
double physMS = sFPS144;
|
||||
double physlag = 0;
|
||||
double renderMS = sFPS144;
|
||||
double renderlag = 0;
|
||||
|
||||
struct mCamera camera = {0};
|
||||
|
||||
|
@ -27,63 +24,47 @@ int main(int argc, char **args)
|
|||
|
||||
engine_init();
|
||||
|
||||
struct mSDLWindow *window = MakeSDLWindow("Untitled Game", 1920, 1080,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
|
||||
struct mSDLWindow *window = MakeSDLWindow("Untitled Game", 1920, 1080, 0);
|
||||
|
||||
openglInit();
|
||||
|
||||
|
||||
editor_init(window);
|
||||
|
||||
|
||||
int quit = 0;
|
||||
SDL_Event e;
|
||||
|
||||
//While application is running
|
||||
while (!quit) {
|
||||
frameTick = SDL_GetTicks();
|
||||
elapsed = frameTick - lastTick;
|
||||
lastTick = frameTick;
|
||||
deltaT = elapsed / 1000.f;
|
||||
deltaT = elapsed_time();
|
||||
|
||||
physlag += elapsed;
|
||||
renderlag += elapsed;
|
||||
physlag += deltaT;
|
||||
renderlag += deltaT;
|
||||
|
||||
input_poll();
|
||||
|
||||
if (physlag >= physMS) {
|
||||
phys2d_update(physMS / 1000.f);
|
||||
phys2d_update(physMS);
|
||||
|
||||
physlag -= physMS;
|
||||
}
|
||||
|
||||
|
||||
if (renderlag >= renderMS) {
|
||||
if (physOn) {
|
||||
update_gameobjects();
|
||||
}
|
||||
|
||||
|
||||
camera_2d_update(&camera, renderMS / 1000.f);
|
||||
camera_2d_update(&camera, renderMS);
|
||||
|
||||
openglRender(window, &camera);
|
||||
|
||||
|
||||
|
||||
editor_render();
|
||||
|
||||
|
||||
window_swap(window);
|
||||
|
||||
renderlag -= renderMS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
engine_stop();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue