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
|
UNAME_P != uname -m
|
||||||
|
|
||||||
#CC specifies which compiler we're using
|
#CC specifies which compiler we're using
|
||||||
CC = clang
|
CC = clang -std=c99
|
||||||
CXX = clang++
|
CXX = clang++
|
||||||
|
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
|
@ -58,7 +58,7 @@ ehead != $(call findindir,./source/engine,*.h)
|
||||||
eobjects != $(call make_objs, ./source/engine)
|
eobjects != $(call make_objs, ./source/engine)
|
||||||
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine.c yugine.c)
|
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)
|
imguiobjs != $(call prefix,$(imguisrcs),$(objprefix)/source/editor/imgui/,.o)
|
||||||
|
|
||||||
eddirs != find ./source/editor -type d
|
eddirs != find ./source/editor -type d
|
||||||
|
@ -79,8 +79,8 @@ includeflag != $(call prefix,$(edirs) $(eddirs) $(pindirs) $(bsdirs),-I)
|
||||||
COMPINCLUDE = $(edirs) $(eddirs) $(pindirs) $(bsdirs)
|
COMPINCLUDE = $(edirs) $(eddirs) $(pindirs) $(bsdirs)
|
||||||
|
|
||||||
#COMPILER_FLAGS specifies the additional compilation options we're using
|
#COMPILER_FLAGS specifies the additional compilation options we're using
|
||||||
WARNING_FLAGS = -w #-pedantic -Wall -Wextra -Wwrite-strings
|
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 -c -MMD -MP $< -o $@
|
COMPILER_FLAGS = $(includeflag) -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c -MMD -MP $< -o $@
|
||||||
|
|
||||||
LIBPATH = -L./bin
|
LIBPATH = -L./bin
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ ifeq ($(UNAME), Windows_NT)
|
||||||
else
|
else
|
||||||
LINKER_FLAGS =
|
LINKER_FLAGS =
|
||||||
ELIBS = editor engine
|
ELIBS = editor engine
|
||||||
CLIBS = SDL2 SDL2_mixer GLEW GL dl pthread
|
CLIBS = glfw SDL2 SDL2_mixer dl pthread
|
||||||
EXT =
|
EXT =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -119,10 +119,13 @@ LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
|
||||||
engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
|
engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
|
||||||
@echo Linking engine
|
@echo Linking engine
|
||||||
@$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
@$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
||||||
|
@echo Finished build
|
||||||
|
|
||||||
editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
|
editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
|
||||||
@echo Linking editor
|
@echo Linking editor
|
||||||
$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
$(CXX) $< $(linkinclude:%=-I%) $(LINK)
|
||||||
|
@mv editor yugine/editor
|
||||||
|
@echo Finished build
|
||||||
|
|
||||||
$(ENGINE): $(eobjects)
|
$(ENGINE): $(eobjects)
|
||||||
@echo Making library engine.a
|
@echo Making library engine.a
|
||||||
|
@ -147,12 +150,12 @@ pinball: $(ENGINE) $(pinobjects)
|
||||||
$(objprefix)/%.o:%.cpp
|
$(objprefix)/%.o:%.cpp
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@echo Making C++ object $@
|
@echo Making C++ object $@
|
||||||
@$(CXX) $(COMPILER_FLAGS)
|
-@$(CXX) $(COMPILER_FLAGS)
|
||||||
|
|
||||||
$(objprefix)/%.o:%.c
|
$(objprefix)/%.o:%.c
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@echo Making C object $@
|
@echo Making C object $@
|
||||||
@$(CC) $(COMPILER_FLAGS)
|
-@$(CC) $(COMPILER_FLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo Cleaning project
|
@echo Cleaning project
|
||||||
|
|
|
@ -5,4 +5,4 @@ unsigned long long triCount = 0;
|
||||||
void resetTriangles()
|
void resetTriangles()
|
||||||
{
|
{
|
||||||
triCount = 0;
|
triCount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include "openglrender.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
@ -12,7 +13,6 @@ extern "C" {
|
||||||
#include "editorstate.h"
|
#include "editorstate.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "openglrender.h"
|
|
||||||
#include "2dphysics.h"
|
#include "2dphysics.h"
|
||||||
#include "debugdraw.h"
|
#include "debugdraw.h"
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
|
@ -20,7 +20,6 @@ extern "C" {
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include <chipmunk/chipmunk.h>
|
#include <chipmunk/chipmunk.h>
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "pinball.h"
|
#include "pinball.h"
|
||||||
|
@ -32,20 +31,13 @@ extern "C" {
|
||||||
#include <stb_ds.h>
|
#include <stb_ds.h>
|
||||||
#define ASSET_TEXT_BUF 1024*1024 /* 1 MB buffer for editing text files */
|
#define ASSET_TEXT_BUF 1024*1024 /* 1 MB buffer for editing text files */
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui_impl_sdl.h>
|
#include <imgui_impl_glfw.h>
|
||||||
#include <imgui_impl_opengl3.h>
|
#include <imgui_impl_opengl3.h>
|
||||||
struct gameproject *cur_project;
|
struct gameproject *cur_project;
|
||||||
struct vec *projects;
|
struct vec *projects;
|
||||||
static char setpath[MAXPATH];
|
static char setpath[MAXPATH];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
// TODO: Pack this into a bitfield
|
// TODO: Pack this into a bitfield
|
||||||
static struct editorVars editor = { 0 };
|
static struct editorVars editor = { 0 };
|
||||||
|
@ -55,14 +47,11 @@ bool flashlightOn = false;
|
||||||
// Lighting effect flags
|
// Lighting effect flags
|
||||||
static bool renderAO = true;
|
static bool renderAO = true;
|
||||||
static bool renderDynamicShadows = true;
|
static bool renderDynamicShadows = true;
|
||||||
static bool renderRefraction = true;
|
|
||||||
static bool renderReflection = true;
|
|
||||||
|
|
||||||
// Debug render modes
|
// Debug render modes
|
||||||
static bool renderGizmos = false;
|
static bool renderGizmos = false;
|
||||||
static bool showGrid = true;
|
static bool showGrid = true;
|
||||||
static bool debugDrawPhysics = false;
|
static bool debugDrawPhysics = false;
|
||||||
static bool renderNav = false;
|
|
||||||
|
|
||||||
const char *allowed_extensions[] = { "jpg", "png", "gltf", "glsl" };
|
const char *allowed_extensions[] = { "jpg", "png", "gltf", "glsl" };
|
||||||
|
|
||||||
|
@ -79,10 +68,6 @@ struct fileasset *selected_asset;
|
||||||
|
|
||||||
static int selected_index = -1;
|
static int selected_index = -1;
|
||||||
|
|
||||||
static struct mCamera camera = { 0 };
|
|
||||||
|
|
||||||
static int tex_view = 0;
|
|
||||||
|
|
||||||
static int grid1_width = 1;
|
static int grid1_width = 1;
|
||||||
static int grid1_span = 100;
|
static int grid1_span = 100;
|
||||||
static int grid2_width = 3;
|
static int grid2_width = 3;
|
||||||
|
@ -260,6 +245,155 @@ void editor_save()
|
||||||
fclose(feditor);
|
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)
|
void editor_init(struct mSDLWindow *window)
|
||||||
{
|
{
|
||||||
projects = vec_make(sizeof(struct gameproject), 5);
|
projects = vec_make(sizeof(struct gameproject), 5);
|
||||||
|
@ -276,197 +410,24 @@ void editor_init(struct mSDLWindow *window)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO & io = ImGui::GetIO();
|
|
||||||
(void) io;
|
|
||||||
ImGui::StyleColorsClassic();
|
ImGui::StyleColorsClassic();
|
||||||
ImGui_ImplSDL2_InitForOpenGL(window->window, window->glContext);
|
ImGui_ImplGlfw_InitForOpenGL(window->window, true);
|
||||||
ImGui_ImplOpenGL3_Init();
|
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();
|
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()
|
int editor_wantkeyboard()
|
||||||
{
|
{
|
||||||
|
if (io == NULL) return 0;
|
||||||
return io->WantCaptureKeyboard;
|
return io->WantCaptureKeyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,7 +550,7 @@ void editor_project_gui()
|
||||||
if (editor.showStats) {
|
if (editor.showStats) {
|
||||||
ImGui::Begin("Stats", &editor.showStats);
|
ImGui::Begin("Stats", &editor.showStats);
|
||||||
ImGui::Text("FPS: %2.4f", 1.f / deltaT);
|
ImGui::Text("FPS: %2.4f", 1.f / deltaT);
|
||||||
ImGui::Text("Triangles rendered: %d", triCount);
|
ImGui::Text("Triangles rendered: %llu", triCount);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +750,7 @@ void editor_project_gui()
|
||||||
void editor_render()
|
void editor_render()
|
||||||
{
|
{
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
|
||||||
|
@ -817,7 +778,7 @@ void pickGameObject(int pickID)
|
||||||
|
|
||||||
int is_allowed_extension(const char *ext)
|
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 < sizeof(allowed_extensions) / sizeof(allowed_extensions[0]);
|
||||||
i++) {
|
i++) {
|
||||||
if (!strcmp(ext + 1, allowed_extensions[i]))
|
if (!strcmp(ext + 1, allowed_extensions[i]))
|
||||||
|
@ -1019,7 +980,7 @@ void editor_project_btn_gui(struct gameproject *gp)
|
||||||
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text(gp->path);
|
ImGui::Text("%s", gp->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void editor_proj_select_gui()
|
void editor_proj_select_gui()
|
||||||
|
@ -1053,7 +1014,7 @@ void editor_init_project(struct gameproject *gp)
|
||||||
|
|
||||||
void editor_make_project(char *path)
|
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 =
|
cur_project =
|
||||||
(struct gameproject *) malloc(sizeof(struct gameproject));
|
(struct gameproject *) malloc(sizeof(struct gameproject));
|
||||||
strncpy(cur_project->name, "New Game", 127);
|
strncpy(cur_project->name, "New Game", 127);
|
||||||
|
@ -1069,7 +1030,7 @@ void editor_make_project(char *path)
|
||||||
|
|
||||||
void editor_import_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)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1133,7 +1094,7 @@ void staticactor_gui(struct mStaticActor *sa)
|
||||||
object_gui(&sa->obj);
|
object_gui(&sa->obj);
|
||||||
if (ImGui::CollapsingHeader("Model")) {
|
if (ImGui::CollapsingHeader("Model")) {
|
||||||
ImGui::Checkbox("Cast Shadows", &sa->castShadows);
|
ImGui::Checkbox("Cast Shadows", &sa->castShadows);
|
||||||
ImGui::Text("Model path", &sa->currentModelPath);
|
ImGui::Text("Model path: %s", sa->currentModelPath);
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Load model")) {
|
if (ImGui::Button("Load model")) {
|
||||||
|
@ -1237,10 +1198,6 @@ void object_gui(struct mGameObject *go)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define EDITOR_H
|
#define EDITOR_H
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
|
||||||
|
@ -41,12 +40,13 @@ struct gameproject {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Texture;
|
struct Texture;
|
||||||
|
struct mSDLWindow;
|
||||||
|
|
||||||
void pickGameObject(int pickID);
|
void pickGameObject(int pickID);
|
||||||
int is_allowed_extension(const char *ext);
|
int is_allowed_extension(const char *ext);
|
||||||
|
|
||||||
void editor_init(struct mSDLWindow *window);
|
void editor_init(struct mSDLWindow *window);
|
||||||
void editor_input(struct mSDLWindow *window, SDL_Event * e);
|
void editor_input();
|
||||||
void editor_render();
|
void editor_render();
|
||||||
int editor_wantkeyboard();
|
int editor_wantkeyboard();
|
||||||
void editor_save();
|
void editor_save();
|
||||||
|
@ -77,6 +77,21 @@ void game_pause();
|
||||||
|
|
||||||
void get_levels();
|
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
|
///////// Object GUIs
|
||||||
void light_gui(struct mLight *light);
|
void light_gui(struct mLight *light);
|
||||||
void pointlight_gui(struct mPointLight *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)
|
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 =
|
box->shape.shape =
|
||||||
cpSpaceAddShape(space,
|
cpSpaceAddShape(space,
|
||||||
cpBoxShapeNew(go->body, box->w, box->h, box->r));
|
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)
|
void phys2d_dbgdrawseg(struct phys2d_segment *seg)
|
||||||
{
|
{
|
||||||
cpVect p = cpBodyGetPosition(seg->shape.go->body);
|
cpVect p = cpBodyGetPosition(seg->shape.go->body);
|
||||||
float s = seg->shape.go->scale;
|
|
||||||
cpVect a = cpSegmentShapeGetA(seg->shape.shape);
|
cpVect a = cpSegmentShapeGetA(seg->shape.shape);
|
||||||
cpVect b = cpSegmentShapeGetB(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;
|
float s = poly->shape.go->scale;
|
||||||
for (int i = 0; i < poly->n; i++) {
|
for (int i = 0; i < poly->n; i++) {
|
||||||
float point[2];
|
|
||||||
float d =
|
float d =
|
||||||
sqrt(pow(poly->points[i * 2] * s, 2.f) +
|
sqrt(pow(poly->points[i * 2] * s, 2.f) +
|
||||||
pow(poly->points[i * 2 + 1] * 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);
|
float angle = cpBodyGetAngle(edge->shape.go->body);
|
||||||
|
|
||||||
for (int i = 0; i < edge->n; i++) {
|
for (int i = 0; i < edge->n; i++) {
|
||||||
float point[2];
|
|
||||||
float d =
|
float d =
|
||||||
sqrt(pow(edge->points[i * 2] * s, 2.f) +
|
sqrt(pow(edge->points[i * 2] * s, 2.f) +
|
||||||
pow(edge->points[i * 2 + 1] * s, 2.f));
|
pow(edge->points[i * 2 + 1] * s, 2.f));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#ifndef THREEDPHYSICS_H
|
#ifndef THREEDPHYSICS_H
|
||||||
#define THREEDPHYSICS_H
|
#define THREEDPHYSICS_H
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "gameobject.h"
|
#include "gameobject.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
const float CAMERA_MINSPEED = 1.f;
|
const float CAMERA_MINSPEED = 1.f;
|
||||||
const float CAMERA_MAXSPEED = 300.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)
|
void camera_2d_update(struct mCamera *camera, float deltaT)
|
||||||
{
|
{
|
||||||
static mfloat_t holdvec[3];
|
|
||||||
static mfloat_t frame[3];
|
static mfloat_t frame[3];
|
||||||
vec3_zero(frame);
|
vec3_zero(frame);
|
||||||
|
if (action_down(GLFW_KEY_W))
|
||||||
if (currentKeystates[SDL_SCANCODE_W])
|
|
||||||
vec3_add(frame, frame, UP);
|
vec3_add(frame, frame, UP);
|
||||||
if (currentKeystates[SDL_SCANCODE_S])
|
if (action_down(GLFW_KEY_S))
|
||||||
vec3_add(frame, frame, DOWN);
|
vec3_add(frame, frame, DOWN);
|
||||||
if (currentKeystates[SDL_SCANCODE_A])
|
if (action_down(GLFW_KEY_A))
|
||||||
vec3_add(frame, frame, LEFT);
|
vec3_add(frame, frame, LEFT);
|
||||||
if (currentKeystates[SDL_SCANCODE_D])
|
if (action_down(GLFW_KEY_D))
|
||||||
vec3_add(frame, frame, RIGHT);
|
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)) {
|
if (!vec3_is_zero(frame)) {
|
||||||
vec3_normalize(frame, frame);
|
vec3_normalize(frame, frame);
|
||||||
|
|
|
@ -18,4 +18,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "datastream.h"
|
#include "datastream.h"
|
||||||
|
|
||||||
#include <pl_mpeg.h>
|
#include "render.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
#include <GL/glew.h>
|
#include "sound.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static void ds_update_texture(uint32_t unit, uint32_t texture,
|
static void ds_update_texture(uint32_t unit, uint32_t texture,
|
||||||
plm_plane_t * plane)
|
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;
|
struct datastream *ds = (struct datastream *) user;
|
||||||
int size = sizeof(float) * samples->count * 2;
|
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,
|
void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
|
||||||
const char *adriver)
|
|
||||||
{
|
{
|
||||||
ds_stop(ds);
|
ds_stop(ds);
|
||||||
char buf[MAXPATH] = {'\0'};
|
char buf[MAXPATH] = {'\0'};
|
||||||
|
@ -42,12 +41,10 @@ void ds_openvideo(struct datastream *ds, const char *video,
|
||||||
ds->plm = plm_create_with_filename(buf);
|
ds->plm = plm_create_with_filename(buf);
|
||||||
|
|
||||||
if (!ds->plm) {
|
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);
|
YughLog(0, 0, "Opened %s - framerate: %f, samplerate: %d, duration: %f",
|
||||||
|
|
||||||
SDL_Log("Opened %s - framerate: %f, samplerate: %d, duration: %f",
|
|
||||||
video,
|
video,
|
||||||
plm_get_framerate(ds->plm),
|
plm_get_framerate(ds->plm),
|
||||||
plm_get_samplerate(ds->plm), plm_get_duration(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_enabled(ds->plm, true);
|
||||||
plm_set_audio_stream(ds->plm, 0);
|
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
|
// Adjust the audio lead time according to the audio_spec buffer size
|
||||||
//plm_set_audio_lead_time(plm, (double)audio_spec.samples / (double)samplerate);
|
//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)
|
void ds_seek(struct datastream *ds, uint32_t time)
|
||||||
{
|
{
|
||||||
SDL_ClearQueuedAudio(0);
|
clear_raw(ds->audio_device);
|
||||||
plm_seek(ds->plm, time, false);
|
plm_seek(ds->plm, time, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +130,7 @@ void ds_stop(struct datastream *ds)
|
||||||
ds->plm = NULL;
|
ds->plm = NULL;
|
||||||
}
|
}
|
||||||
if (ds->audio_device)
|
if (ds->audio_device)
|
||||||
SDL_CloseAudioDevice(ds->audio_device);
|
close_audio_device(ds->audio_device);
|
||||||
ds->playing = false;
|
ds->playing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,4 +152,4 @@ double ds_remainingtime(struct datastream *ds)
|
||||||
double ds_length(struct datastream *ds)
|
double ds_length(struct datastream *ds)
|
||||||
{
|
{
|
||||||
return plm_get_duration(ds->plm);
|
return plm_get_duration(ds->plm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
#ifndef DATASTREAM_H
|
#ifndef DATASTREAM_H
|
||||||
#define DATASTREAM_H
|
#define DATASTREAM_H
|
||||||
|
|
||||||
#include <SDL2/SDL_audio.h>
|
#include <stdint.h>
|
||||||
|
#include <pl_mpeg.h>
|
||||||
typedef struct plm_t plm_t;
|
|
||||||
|
|
||||||
|
|
||||||
struct datastream {
|
struct datastream {
|
||||||
plm_t *plm;
|
plm_t *plm;
|
||||||
struct mShader *shader;
|
struct mShader *shader;
|
||||||
double last_time;
|
double last_time;
|
||||||
int playing;
|
int playing;
|
||||||
SDL_AudioDeviceID audio_device;
|
int audio_device;
|
||||||
uint32_t texture_y;
|
uint32_t texture_y;
|
||||||
uint32_t texture_cb;
|
uint32_t texture_cb;
|
||||||
uint32_t texture_cr;
|
uint32_t texture_cr;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
#define PL_MPEG_IMPLEMENTATION
|
|
||||||
#define CGLTF_IMPLEMENTATION
|
#define CGLTF_IMPLEMENTATION
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#define STB_DS_IMPLEMENTATION
|
#define STB_DS_IMPLEMENTATION
|
||||||
|
@ -14,8 +13,8 @@
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#include <pl_mpeg.h>
|
#include <pl_mpeg.h>
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include "render.h"
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include "openglrender.h"
|
#include "openglrender.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
@ -26,51 +25,47 @@
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "script.h"
|
||||||
|
#include "vec.h"
|
||||||
|
#include "sound.h"
|
||||||
|
|
||||||
// TODO: Init on the heap
|
// TODO: Init on the heap
|
||||||
|
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
|
void error_callback(int error, const char *description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
|
}
|
||||||
|
|
||||||
void engine_init()
|
void engine_init()
|
||||||
{
|
{
|
||||||
|
/* Initialize GLFW */
|
||||||
|
if (!glfwInit()) {
|
||||||
//Initialize SDL
|
printf("Could not init GLFW\n");
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
//Use OpenGL 3.3
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
resources_init();
|
resources_init();
|
||||||
script_init();
|
script_init();
|
||||||
registry_init();
|
registry_init();
|
||||||
init_gameobjects();
|
init_gameobjects();
|
||||||
|
timer_init();
|
||||||
|
|
||||||
prefabs = vec_make(MAXNAME, 25);
|
prefabs = vec_make(MAXNAME, 25);
|
||||||
stbi_set_flip_vertically_on_load(1);
|
stbi_set_flip_vertically_on_load(1);
|
||||||
phys2d_init();
|
phys2d_init();
|
||||||
gui_init();
|
gui_init();
|
||||||
sound_init();
|
sound_init();
|
||||||
|
|
||||||
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void engine_stop()
|
void engine_stop()
|
||||||
{
|
{
|
||||||
SDL_StopTextInput();
|
glfwTerminate();
|
||||||
SDL_Quit();
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
|
|
||||||
#define FPS30 33
|
#define FPS30 33
|
||||||
#define FPS60 17
|
#define FPS60 17
|
||||||
#define FPS120 8;
|
#define FPS120 8
|
||||||
#define FPS144 7
|
#define FPS144 7
|
||||||
#define FPS300 3
|
#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_init();
|
||||||
void engine_stop();
|
void engine_stop();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
#include <shader.h>
|
#include <shader.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
@ -33,7 +33,7 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
||||||
snprintf(fontpath, 256, "fonts/%s", fontfile);
|
snprintf(fontpath, 256, "fonts/%s", fontfile);
|
||||||
|
|
||||||
stbtt_fontinfo fontinfo = { 0 };
|
stbtt_fontinfo fontinfo = { 0 };
|
||||||
int i, j, ascent, baseline, ch = 0;
|
int ascent = 0;
|
||||||
|
|
||||||
stbtt_InitFont(&fontinfo, ttf_buffer, 0);
|
stbtt_InitFont(&fontinfo, ttf_buffer, 0);
|
||||||
stbtt_GetFontVMetrics(&fontinfo, &ascent, 0, 0);
|
stbtt_GetFontVMetrics(&fontinfo, &ascent, 0, 0);
|
||||||
|
@ -164,10 +164,6 @@ void text_settype(struct sFont *mfont)
|
||||||
font = 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)
|
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw)
|
||||||
{
|
{
|
||||||
shader_use(shader);
|
shader_use(shader);
|
||||||
|
@ -181,8 +177,8 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
char *line, *wordstart;
|
const unsigned char *line, *wordstart;
|
||||||
line = text;
|
line = (unsigned char*)text;
|
||||||
|
|
||||||
|
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <chipmunk/chipmunk.h>
|
#include <chipmunk/chipmunk.h>
|
||||||
|
#include "resources.h"
|
||||||
|
|
||||||
struct vec *gameobjects = NULL;
|
struct vec *gameobjects = NULL;
|
||||||
struct mGameObject *updateGO = NULL;
|
struct mGameObject *updateGO = NULL;
|
||||||
|
@ -186,7 +187,7 @@ void gameobject_update(struct mGameObject *go)
|
||||||
script_run(updateGO->update);
|
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)
|
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() {
|
void update_gameobjects() {
|
||||||
vec_walk(gameobjects, gameobject_update);
|
vec_walk(gameobjects, &gameobject_update);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
#ifndef GIZMO_H
|
#ifndef GIZMO_H
|
||||||
#define GIZMO_H
|
#define GIZMO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct gizmo {
|
||||||
|
uint8_t color[3];
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,17 +1,35 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
#include "window.h"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
int32_t mouseWheelX = 0;
|
int32_t mouseWheelX = 0;
|
||||||
int32_t mouseWheelY = 0;
|
int32_t mouseWheelY = 0;
|
||||||
int ychange = 0;
|
int ychange = 0;
|
||||||
int xchange = 0;
|
int xchange = 0;
|
||||||
float deltaT = 0;
|
float deltaT = 0;
|
||||||
int quit = 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()
|
void input_poll()
|
||||||
{
|
{
|
||||||
|
@ -19,15 +37,25 @@ void input_poll()
|
||||||
xchange = 0;
|
xchange = 0;
|
||||||
mouseWheelX = 0;
|
mouseWheelX = 0;
|
||||||
mouseWheelY = 0;
|
mouseWheelY = 0;
|
||||||
currentKeystates = SDL_GetKeyboardState(NULL);
|
|
||||||
|
|
||||||
while (SDL_PollEvent(&e)) {
|
glfwPollEvents();
|
||||||
window_all_handle_events(&e);
|
|
||||||
|
|
||||||
#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
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
extern int32_t mouseWheelX;
|
extern int32_t mouseWheelX;
|
||||||
extern int32_t mouseWheelY;
|
extern int32_t mouseWheelY;
|
||||||
|
@ -10,9 +10,19 @@ extern int ychange;
|
||||||
extern int xchange;
|
extern int xchange;
|
||||||
extern float deltaT;
|
extern float deltaT;
|
||||||
extern int quit;
|
extern int quit;
|
||||||
extern SDL_Event e;
|
|
||||||
extern uint8_t *currentKeystates;
|
|
||||||
|
|
||||||
|
void input_init();
|
||||||
void input_poll();
|
void input_poll();
|
||||||
|
|
||||||
|
void cursor_hide();
|
||||||
|
void cursor_show();
|
||||||
|
|
||||||
|
int action_down(int scancode);
|
||||||
|
|
||||||
|
struct inputaction
|
||||||
|
{
|
||||||
|
int scancode;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
#include "gameobject.h"
|
#include "gameobject.h"
|
||||||
|
#include "resources.h"
|
||||||
|
|
||||||
void save_level(char name[MAXNAME])
|
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);
|
shader_setfloat(shader, "spotLight.constant", light->constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
#ifndef LIGHT_H
|
#ifndef LIGHT_H
|
||||||
#define LIGHT_H
|
#define LIGHT_H
|
||||||
|
|
||||||
/*
|
#include <stdint.h>
|
||||||
|
|
||||||
struct mLight {
|
struct mLight {
|
||||||
struct mGameObject obj;
|
struct mGameObject *go;
|
||||||
mfloat_t color[3];
|
uint8_t color[3];
|
||||||
float strength;
|
float strength;
|
||||||
int dynamic;
|
int dynamic;
|
||||||
int on;
|
int on;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
struct mPointLight {
|
struct mPointLight {
|
||||||
struct mLight light;
|
struct mLight light;
|
||||||
float constant;
|
float constant;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
#define logLevel 4
|
#define logLevel 4
|
||||||
|
|
||||||
void mYughLog(int category, int priority, const char *message,
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||||
int line, const char *file, ...)
|
|
||||||
{
|
{
|
||||||
if (priority >= logLevel) {
|
if (priority >= logLevel) {
|
||||||
time_t now = time(0);
|
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",
|
snprintf(buffer, ERROR_BUFFER, "LEVEL %d :: %s [ %s:%d ] %s\n",
|
||||||
priority, msgbuffer, file, line, dt);
|
priority, msgbuffer, file, line, dt);
|
||||||
|
|
||||||
//SDL_LogMessage(category, priority, buffer);
|
printf("%s", buffer);
|
||||||
printf(buffer);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,19 +36,8 @@ void FlushGLErrors()
|
||||||
GLenum glErr = GL_NO_ERROR;
|
GLenum glErr = GL_NO_ERROR;
|
||||||
glErr = glGetError();
|
glErr = glGetError();
|
||||||
while (glErr != GL_NO_ERROR) {
|
while (glErr != GL_NO_ERROR) {
|
||||||
YughLog(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_ERROR,
|
YughLog(0, 3,
|
||||||
"GL Error: %d", glErr);
|
"GL Error: %d", glErr);
|
||||||
glErr = glGetError();
|
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
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
|
|
||||||
#define ERROR_BUFFER 2048
|
#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,
|
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, __VA_ARGS__)
|
||||||
int line, const char *file, ...);
|
|
||||||
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...);
|
||||||
|
|
||||||
void FlushGLErrors();
|
void FlushGLErrors();
|
||||||
|
|
||||||
int TestSDLError(int sdlErr);
|
int TestSDLError(int sdlErr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -44,8 +44,6 @@ const mint_t VEC3I_ONE[3] = { 1, 1, 1 };
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef float mfloat_t;
|
|
||||||
|
|
||||||
#if defined(MATHC_USE_INT)
|
#if defined(MATHC_USE_INT)
|
||||||
mint_t clampi(mint_t value, mint_t min, mint_t max)
|
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);
|
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 squat_from_euler(mfloat_t x, mfloat_t y, mfloat_t z)
|
||||||
{
|
{
|
||||||
struct quat result;
|
struct quat result = {0};
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
void DrawMesh(struct mMesh *mesh, struct mShader *shader)
|
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++) {
|
for (uint32_t i = 0; i < (mesh->te - mesh->textures); i++) {
|
||||||
glActiveTexture(GL_TEXTURE0 + i); // active proper texture unit before binding
|
glActiveTexture(GL_TEXTURE0 + i); // active proper texture unit before binding
|
||||||
// retrieve texture number (the N in diffuse_textureN)
|
// retrieve texture number (the N in diffuse_textureN)
|
||||||
char number;
|
char number = 0;
|
||||||
// TODO: malloc every single frame ... nope! Change to stack
|
// TODO: malloc every single frame ... nope! Change to stack
|
||||||
char *name =
|
/*char *name =
|
||||||
(char *) malloc(sizeof(char) *
|
(char *) malloc(sizeof(char) *
|
||||||
(strlen(mesh->textures[i].type) + 2));
|
(strlen(mesh->textures[i].type) + 2));*/
|
||||||
if (mesh->textures[i].type == "texture_diffuse")
|
if (mesh->textures[i].type == TEX_DIFF)
|
||||||
number = diffuseNr++;
|
number = diffuseNr++;
|
||||||
else if (mesh->textures[i].type == "texture_specular")
|
else if (mesh->textures[i].type == TEX_SPEC)
|
||||||
number = specularNr++;
|
number = specularNr++;
|
||||||
else if (mesh->textures[i].type == "texture_normal")
|
else if (mesh->textures[i].type == TEX_NORM)
|
||||||
number = normalNr++;
|
number = normalNr++;
|
||||||
else if (mesh->textures[i].type == "texture_height")
|
else if (mesh->textures[i].type == TEX_HEIGHT)
|
||||||
number = heightNr++;
|
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);
|
glUniform1i(glGetUniformLocation(shader->id, name), i);
|
||||||
// and finally bind the texture
|
|
||||||
glBindTexture(GL_TEXTURE_2D, mesh->textures[i].id);
|
glBindTexture(GL_TEXTURE_2D, mesh->textures[i].id);
|
||||||
free(name);
|
free(name);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw mesh
|
// draw mesh
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include <cgltf.h>
|
#include <cgltf.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static struct mModel *lastRendered;
|
static struct mModel *lastRendered;
|
||||||
static struct mModel *loadedModels[100];
|
static struct mModel *loadedModels[100];
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "openglrender.h"
|
#include "openglrender.h"
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
@ -15,7 +14,7 @@
|
||||||
int renderMode = 0;
|
int renderMode = 0;
|
||||||
|
|
||||||
static GLuint UBO;
|
static GLuint UBO;
|
||||||
static GLuint UBOBind = 0;
|
|
||||||
|
|
||||||
static GLuint gridVBO = 0;
|
static GLuint gridVBO = 0;
|
||||||
static GLuint gridVAO = 0;
|
static GLuint gridVAO = 0;
|
||||||
|
@ -84,22 +83,17 @@ bool renderReflection = true;
|
||||||
struct mGameObject *selectedobject = NULL;
|
struct mGameObject *selectedobject = NULL;
|
||||||
char objectName[200] = { '\0' }; // object name buffer
|
char objectName[200] = { '\0' }; // object name buffer
|
||||||
|
|
||||||
uint16_t debugColorPickBO = 0;
|
GLuint debugColorPickBO = 0;
|
||||||
uint16_t debugColorPickTEX = 0;
|
GLuint debugColorPickTEX = 0;
|
||||||
|
|
||||||
|
|
||||||
struct mSprite *tsprite = NULL;
|
struct mSprite *tsprite = NULL;
|
||||||
static struct mSprite *tanim = NULL;
|
|
||||||
|
|
||||||
static unsigned int projUBO;
|
static unsigned int projUBO;
|
||||||
|
|
||||||
void openglInit()
|
void openglInit()
|
||||||
{
|
{
|
||||||
if (SDL_GL_SetSwapInterval(1)) {
|
|
||||||
YughLog(0, SDL_LOG_PRIORITY_WARN,
|
|
||||||
"Unable to set VSync! SDL Error: %s", SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
sprite_initialize();
|
sprite_initialize();
|
||||||
|
|
||||||
////// MAKE SHADERS
|
////// MAKE SHADERS
|
||||||
|
@ -222,34 +216,7 @@ void openglRender(struct mSDLWindow *window, struct mCamera *mcamera)
|
||||||
|
|
||||||
void openglInit3d(struct mSDLWindow *window)
|
void openglInit3d(struct mSDLWindow *window)
|
||||||
{
|
{
|
||||||
//Initialize SDL
|
/* TODO: IMG init doesn't work in C++
|
||||||
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+
|
|
||||||
int init =(0x00000001 | 0x00000002);
|
int init =(0x00000001 | 0x00000002);
|
||||||
int initted =IMG_Init(init);
|
int initted =IMG_Init(init);
|
||||||
YughLog(0, SDL_LOG_PRIORITY_ERROR, "Init flags: %d\nInitted values: %d ", init, initted);
|
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);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Configure matrices with an orthogonal
|
// Configure matrices with an orthogonal
|
||||||
mfloat_t lightView[16] = { 0.f };
|
|
||||||
mfloat_t lightSpaceMatrix[16] = { 0.f };
|
mfloat_t lightSpaceMatrix[16] = { 0.f };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define OPENGL_RENDER_H
|
#define OPENGL_RENDER_H
|
||||||
|
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "window.h"
|
|
||||||
|
|
||||||
struct mCamera;
|
struct mCamera;
|
||||||
struct mSDLWindow;
|
struct mSDLWindow;
|
||||||
|
@ -31,7 +30,7 @@ extern float plane_size;
|
||||||
extern float near_plane;
|
extern float near_plane;
|
||||||
extern float far_plane;
|
extern float far_plane;
|
||||||
extern char objectName[];
|
extern char objectName[];
|
||||||
extern uint16_t debugColorPickBO;
|
extern GLuint debugColorPickBO;
|
||||||
|
|
||||||
extern struct mGameObject *selectedobject;
|
extern struct mGameObject *selectedobject;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ int ncomponent = 0;
|
||||||
void registry_init()
|
void registry_init()
|
||||||
{
|
{
|
||||||
register_component("Sprite", sizeof(struct mSprite), &MakeSprite, NULL,
|
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),
|
register_component("2D Circle Collider", sizeof(struct phys2d_circle),
|
||||||
&Make2DCircle, &phys2d_dbgdrawcircle, &circle_gui,
|
&Make2DCircle, &phys2d_dbgdrawcircle, &circle_gui,
|
||||||
&phys2d_circleinit, NULL);
|
&phys2d_circleinit, NULL);
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#ifndef RENDER_H
|
#ifndef RENDER_H
|
||||||
#define RENDER_H
|
#define RENDER_H
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#include <glad/gl.h>
|
||||||
#include <GL/glew.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <SDL2/SDL_opengl.h>
|
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
char *DATA_PATH = NULL;
|
char *DATA_PATH = NULL;
|
||||||
char *PREF_PATH = NULL;
|
char *PREF_PATH = NULL;
|
||||||
|
@ -22,7 +23,6 @@ const char *EXT_LEVEL = ".level";
|
||||||
int stemlen = 0;
|
int stemlen = 0;
|
||||||
|
|
||||||
static const char *cur_ext = NULL;
|
static const char *cur_ext = NULL;
|
||||||
static DIR *cur_dir = NULL;
|
|
||||||
struct dirent *c_dirent = NULL;
|
struct dirent *c_dirent = NULL;
|
||||||
struct vec *c_vec = NULL;
|
struct vec *c_vec = NULL;
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@ void resources_init()
|
||||||
getcwd(DATA_PATH, 256);
|
getcwd(DATA_PATH, 256);
|
||||||
strncat(DATA_PATH, "/", 256);
|
strncat(DATA_PATH, "/", 256);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PREF_PATH = SDL_GetPrefPath("Odplot", "Test Game");
|
|
||||||
if (!PREF_PATH)
|
if (!PREF_PATH)
|
||||||
PREF_PATH = strdup("./tmp/");
|
PREF_PATH = strdup("./tmp/");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +101,7 @@ void findPrefabs()
|
||||||
fill_extensions(prefabs, DATA_PATH, EXT_PREFAB);
|
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_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
@ -115,9 +112,9 @@ FILE *path_open(const char *fmt, const char *tag, ...)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *make_path(char *file)
|
char *make_path(const char *file)
|
||||||
{
|
{
|
||||||
strncpy(pathbuf, DATA_PATH, MAXPATH);
|
strncpy(pathbuf, DATA_PATH, MAXPATH);
|
||||||
strncat(pathbuf, file, MAXPATH);
|
strncat(pathbuf, file, MAXPATH);
|
||||||
return pathbuf;
|
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_filename_from_path(char *path, int extension);
|
||||||
char *get_directory_from_path(char *path);
|
char *get_directory_from_path(char *path);
|
||||||
FILE *res_open(char *path, const char *tag);
|
FILE *res_open(char *path, const char *tag);
|
||||||
FILE *path_open(const char *fmt, const char *tag, ...);
|
FILE *path_open(const char *tag, const char *fmt, ...);
|
||||||
char *make_path(char *file);
|
char *make_path(const char *file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,4 +51,4 @@ void script_init()
|
||||||
void script_run(const char *script)
|
void script_run(const char *script)
|
||||||
{
|
{
|
||||||
s7_eval_c_string(s7, script);
|
s7_eval_c_string(s7, script);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,4 @@ extern struct s7_scheme *s7;
|
||||||
void script_init();
|
void script_init();
|
||||||
void script_run(const char *script);
|
void script_run(const char *script);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
#include <GL/glew.h>
|
|
||||||
|
|
||||||
#define SHADER_BUF 10000
|
#define SHADER_BUF 10000
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ int shader_compile_error(GLuint shader)
|
||||||
if (success) return 0;
|
if (success) return 0;
|
||||||
|
|
||||||
glGetShaderInfoLog(shader, ERROR_BUFFER, NULL, infoLog);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ int shader_link_error(GLuint shader)
|
||||||
if (success) return 0;
|
if (success) return 0;
|
||||||
|
|
||||||
glGetProgramInfoLog(shader, ERROR_BUFFER, NULL, infoLog);
|
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;
|
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'};
|
char spath[MAXPATH] = {'\0'};
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ void shader_compile_all()
|
||||||
{
|
{
|
||||||
struct mShader **curshader = mshaders;
|
struct mShader **curshader = mshaders;
|
||||||
do {
|
do {
|
||||||
YughLog(0, SDL_LOG_PRIORITY_INFO, "Compiled Shader %d", 1);
|
YughLog(0, LOG_INFO, "Compiled Shader %d", 1);
|
||||||
shader_compile(*curshader);
|
shader_compile(*curshader);
|
||||||
} while (++curshader != lastShader);
|
} while (++curshader != lastShader);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "openglrender.h"
|
#include "openglrender.h"
|
||||||
|
|
||||||
|
@ -71,24 +72,27 @@ struct mSkybox *MakeSkybox(const char *cubemap)
|
||||||
shader_use(newskybox->shader);
|
shader_use(newskybox->shader);
|
||||||
shader_setint(newskybox->shader, "skybox", 0);
|
shader_setint(newskybox->shader, "skybox", 0);
|
||||||
|
|
||||||
|
/*
|
||||||
const char *faces[6] =
|
const char *faces[6] =
|
||||||
{ "right.jpg", "left.jpg", "top.jpg", "bottom.jpg", "front.jpg",
|
{ "right.jpg", "left.jpg", "top.jpg", "bottom.jpg", "front.jpg",
|
||||||
"back.jpg"
|
"back.jpg"
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
glGenTextures(1, &newskybox->id);
|
glGenTextures(1, &newskybox->id);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 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++) {
|
for (unsigned int i = 0; i < 6; i++) {
|
||||||
|
/*
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
strcat(buf, cubemap);
|
strcat(buf, cubemap);
|
||||||
strcat(buf, "/");
|
strcat(buf, "/");
|
||||||
strcat(buf, faces[i]);
|
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,
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 2048,
|
||||||
2048, 0, GL_RGB, GL_UNSIGNED_BYTE, data->pixels);
|
2048, 0, GL_RGB, GL_UNSIGNED_BYTE, data->pixels);
|
||||||
SDL_FreeSurface(data);
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
#include "resources.h"
|
||||||
|
|
||||||
const char *audioDriver;
|
const char *audioDriver;
|
||||||
|
|
||||||
|
@ -8,11 +9,13 @@ void sound_init()
|
||||||
{
|
{
|
||||||
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
|
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
|
||||||
int err = Mix_Init(flags);
|
int err = Mix_Init(flags);
|
||||||
if (err&flags != flags) {
|
if ((err&flags) != flags) {
|
||||||
printf("MIX did not init!!");
|
printf("MIX did not init!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
mus_ch = Mix_AllocateChannels(1);
|
mus_ch = Mix_AllocateChannels(1);
|
||||||
|
|
||||||
|
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_open(const char *device)
|
void audio_open(const char *device)
|
||||||
|
@ -91,4 +94,32 @@ void music_stop()
|
||||||
void audio_init()
|
void audio_init()
|
||||||
{
|
{
|
||||||
audioDriver = SDL_GetAudioDeviceName(0,0);
|
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>
|
#include <SDL2/SDL_mixer.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct sound {
|
struct sound {
|
||||||
Mix_Chunk *sound;
|
Mix_Chunk *sound;
|
||||||
unsigned char volume;
|
unsigned char volume;
|
||||||
|
@ -15,10 +13,6 @@ struct music {
|
||||||
unsigned char volume;
|
unsigned char volume;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct player {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const char *audioDriver;
|
extern const char *audioDriver;
|
||||||
|
|
||||||
void sound_init();
|
void sound_init();
|
||||||
|
@ -41,6 +35,11 @@ void music_resume();
|
||||||
void music_pause();
|
void music_pause();
|
||||||
void music_stop();
|
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();
|
void audio_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "timer.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "openglrender.h"
|
#include "openglrender.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
@ -18,14 +19,13 @@ static struct mShader *spriteShader = NULL;
|
||||||
static struct mShader *animSpriteShader = NULL;
|
static struct mShader *animSpriteShader = NULL;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct TextureOptions TEX_SPRITE = { 1, 0 };
|
struct TextureOptions TEX_SPRITE = { 1, 0, 0 };
|
||||||
|
|
||||||
struct mSprite *sprites[100] = { NULL };
|
struct mSprite *sprites[100] = { NULL };
|
||||||
|
|
||||||
int numSprites = 0;
|
int numSprites = 0;
|
||||||
|
|
||||||
static uint32_t quadVAO;
|
static uint32_t quadVAO;
|
||||||
static uint32_t VBO;
|
|
||||||
|
|
||||||
struct mSprite *MakeSprite(struct mGameObject *go)
|
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->tex = texture_loadfromfile(path);
|
||||||
sprite->anim = anim;
|
sprite->anim = anim;
|
||||||
sprite->anim.timer =
|
sprite->anim.timer = timer_make(sprite->anim.ms, &incrementAnimFrame, sprite);
|
||||||
SDL_AddTimer(sprite->anim.ms, incrementAnimFrame, sprite);
|
|
||||||
/*
|
/*
|
||||||
sprite->tex = texture_loadanimfromfile(sprite->tex, path, sprite->anim.frames,
|
sprite->tex = texture_loadanimfromfile(sprite->tex, path, sprite->anim.frames,
|
||||||
sprite->anim.dimensions);
|
sprite->anim.dimensions);
|
||||||
|
@ -71,7 +70,7 @@ void sprite_settex(struct mSprite *sprite, struct Texture *tex)
|
||||||
sprite->tex = 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;
|
sprite->anim.frame = (sprite->anim.frame + 1) % sprite->anim.frames;
|
||||||
return interval;
|
return interval;
|
||||||
|
@ -220,4 +219,4 @@ struct mSprite *gui_makesprite()
|
||||||
{
|
{
|
||||||
struct mSprite *new = MakeSprite(gui_go);
|
struct mSprite *new = MakeSprite(gui_go);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
#ifndef SPRITE_H
|
#ifndef SPRITE_H
|
||||||
#define SPRITE_H
|
#define SPRITE_H
|
||||||
|
|
||||||
#include <SDL2/SDL_timer.h>
|
#include "timer.h"
|
||||||
#include "mathc.h"
|
#include "mathc.h"
|
||||||
|
|
||||||
struct datastream;
|
struct datastream;
|
||||||
struct mGameObject;
|
struct mGameObject;
|
||||||
struct Texture;
|
struct Texture;
|
||||||
|
|
||||||
|
struct timer;
|
||||||
|
|
||||||
struct Anim2D {
|
struct Anim2D {
|
||||||
int frames;
|
int frames;
|
||||||
int frame;
|
int frame;
|
||||||
int dimensions[2];
|
int dimensions[2];
|
||||||
SDL_TimerID timer;
|
struct timer *timer;
|
||||||
int ms;
|
int ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,12 +38,12 @@ void sprite_loadtex(struct mSprite *sprite, const char *path);
|
||||||
void sprite_loadanim(struct mSprite *sprite, const char *path,
|
void sprite_loadanim(struct mSprite *sprite, const char *path,
|
||||||
struct Anim2D anim);
|
struct Anim2D anim);
|
||||||
void sprite_settex(struct mSprite *sprite, struct Texture *tex);
|
void sprite_settex(struct mSprite *sprite, struct Texture *tex);
|
||||||
void sprite_initalize();
|
void sprite_initialize();
|
||||||
void sprite_draw(struct mSprite *sprite);
|
void sprite_draw(struct mSprite *sprite);
|
||||||
void spriteanim_draw(struct mSprite *sprite);
|
void spriteanim_draw(struct mSprite *sprite);
|
||||||
void video_draw(struct datastream *ds, mfloat_t pos[2], mfloat_t size[2],
|
void video_draw(struct datastream *ds, mfloat_t pos[2], mfloat_t size[2],
|
||||||
float rotate, mfloat_t color[3]);
|
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();
|
struct mSprite *gui_makesprite();
|
||||||
void gui_init();
|
void gui_init();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include "render.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#include <stb_ds.h>
|
#include <stb_ds.h>
|
||||||
#include <GL/glew.h>
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
char *key;
|
char *key;
|
||||||
|
@ -59,7 +59,7 @@ struct Texture *texture_loadfromfile(const char *path)
|
||||||
|
|
||||||
void tex_pull(struct Texture *tex)
|
void tex_pull(struct Texture *tex)
|
||||||
{
|
{
|
||||||
uint8_t n;
|
int n;
|
||||||
stbi_set_flip_vertically_on_load(0);
|
stbi_set_flip_vertically_on_load(0);
|
||||||
tex->data = stbi_load(tex->path, &tex->width, &tex->height, &n, 4);
|
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_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex->id);
|
glBindTexture(GL_TEXTURE_2D_ARRAY, tex->id);
|
||||||
glTexImage3D(GL_TEXTURE_2D_ARRAY,
|
glTexImage3D(GL_TEXTURE_2D_ARRAY,
|
||||||
0,
|
0,
|
||||||
|
@ -163,10 +164,11 @@ void tex_gpu_load(struct Texture *tex)
|
||||||
|
|
||||||
SDL_FreeSurface(loadedSurface);
|
SDL_FreeSurface(loadedSurface);
|
||||||
SDL_FreeSurface(tempSurface);
|
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);
|
anim_incr(tex_anim);
|
||||||
|
|
||||||
|
@ -195,9 +197,9 @@ void anim_decr(struct TexAnimation *anim)
|
||||||
void tex_anim_set(struct TexAnimation *anim)
|
void tex_anim_set(struct TexAnimation *anim)
|
||||||
{
|
{
|
||||||
if (anim->playing) {
|
if (anim->playing) {
|
||||||
SDL_RemoveTimer(anim->timer);
|
timer_remove(anim->timer);
|
||||||
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);
|
anim);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -262,9 +264,9 @@ void anim_play(struct TexAnimation *anim)
|
||||||
anim->frame = 0;
|
anim->frame = 0;
|
||||||
|
|
||||||
anim->playing = 1;
|
anim->playing = 1;
|
||||||
SDL_RemoveTimer(anim->timer);
|
timer_remove(anim->timer);
|
||||||
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);
|
anim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +278,7 @@ void anim_stop(struct TexAnimation *anim)
|
||||||
anim->playing = 0;
|
anim->playing = 0;
|
||||||
anim->frame = 0;
|
anim->frame = 0;
|
||||||
anim->pausetime = 0;
|
anim->pausetime = 0;
|
||||||
SDL_RemoveTimer(anim->timer);
|
timer_remove(anim->timer);
|
||||||
tex_anim_calc_uv(anim);
|
tex_anim_calc_uv(anim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +288,7 @@ void anim_pause(struct TexAnimation *anim)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
anim->playing = 0;
|
anim->playing = 0;
|
||||||
SDL_RemoveTimer(anim->timer);
|
timer_remove(anim->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void anim_fwd(struct TexAnimation *anim)
|
void anim_fwd(struct TexAnimation *anim)
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
#ifndef TEXTURE_H
|
#ifndef TEXTURE_H
|
||||||
#define 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 {
|
struct Rect {
|
||||||
float x;
|
float x;
|
||||||
|
@ -14,7 +20,7 @@ struct TexAnimation {
|
||||||
int frame;
|
int frame;
|
||||||
int playing;
|
int playing;
|
||||||
int pausetime;
|
int pausetime;
|
||||||
SDL_TimerID timer;
|
struct timer *timer;
|
||||||
struct Rect uv;
|
struct Rect uv;
|
||||||
struct Texture *tex;
|
struct Texture *tex;
|
||||||
};
|
};
|
||||||
|
@ -33,7 +39,7 @@ struct TextureOptions {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Texture {
|
struct Texture {
|
||||||
char *type;
|
int type;
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
char *path;
|
char *path;
|
||||||
int width;
|
int width;
|
||||||
|
@ -65,7 +71,7 @@ void anim_bkwd(struct TexAnimation *anim);
|
||||||
void anim_incr(struct TexAnimation *anim);
|
void anim_incr(struct TexAnimation *anim);
|
||||||
void anim_decr(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_calc_uv(struct TexAnimation *anim);
|
||||||
void tex_anim_set(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
|
@file win32.c
|
||||||
@brief ENet Win32 system specific functions
|
@brief ENet Win32 system specific functions
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +16,7 @@ enet_initialize (void)
|
||||||
{
|
{
|
||||||
WORD versionRequested = MAKEWORD (1, 1);
|
WORD versionRequested = MAKEWORD (1, 1);
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
if (WSAStartup (versionRequested, & wsaData))
|
if (WSAStartup (versionRequested, & wsaData))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ enet_initialize (void)
|
||||||
HIBYTE (wsaData.wVersion) != 1)
|
HIBYTE (wsaData.wVersion) != 1)
|
||||||
{
|
{
|
||||||
WSACleanup ();
|
WSACleanup ();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
|
||||||
{
|
{
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
struct hostent * hostEntry;
|
struct hostent * hostEntry;
|
||||||
|
|
||||||
in.s_addr = address -> host;
|
in.s_addr = address -> host;
|
||||||
|
|
||||||
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
|
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
|
||||||
if (hostEntry == NULL)
|
if (hostEntry == NULL)
|
||||||
return enet_address_get_host_ip (address, name, nameLength);
|
return enet_address_get_host_ip (address, name, nameLength);
|
||||||
|
@ -280,8 +280,8 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int sinLength = sizeof (struct sockaddr_in);
|
int sinLength = sizeof (struct sockaddr_in);
|
||||||
|
|
||||||
result = accept (socket,
|
result = accept (socket,
|
||||||
address != NULL ? (struct sockaddr *) & sin : NULL,
|
address != NULL ? (struct sockaddr *) & sin : NULL,
|
||||||
address != NULL ? & sinLength : NULL);
|
address != NULL ? & sinLength : NULL);
|
||||||
|
|
||||||
if (result == INVALID_SOCKET)
|
if (result == INVALID_SOCKET)
|
||||||
|
@ -327,7 +327,7 @@ enet_socket_send (ENetSocket socket,
|
||||||
sin.sin_addr.s_addr = address -> host;
|
sin.sin_addr.s_addr = address -> host;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WSASendTo (socket,
|
if (WSASendTo (socket,
|
||||||
(LPWSABUF) buffers,
|
(LPWSABUF) buffers,
|
||||||
(DWORD) bufferCount,
|
(DWORD) bufferCount,
|
||||||
& sentLength,
|
& sentLength,
|
||||||
|
@ -406,10 +406,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
||||||
fd_set readSet, writeSet;
|
fd_set readSet, writeSet;
|
||||||
struct timeval timeVal;
|
struct timeval timeVal;
|
||||||
int selectCount;
|
int selectCount;
|
||||||
|
|
||||||
timeVal.tv_sec = timeout / 1000;
|
timeVal.tv_sec = timeout / 1000;
|
||||||
timeVal.tv_usec = (timeout % 1000) * 1000;
|
timeVal.tv_usec = (timeout % 1000) * 1000;
|
||||||
|
|
||||||
FD_ZERO (& readSet);
|
FD_ZERO (& readSet);
|
||||||
FD_ZERO (& writeSet);
|
FD_ZERO (& writeSet);
|
||||||
|
|
||||||
|
@ -431,12 +431,11 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
||||||
|
|
||||||
if (FD_ISSET (socket, & writeSet))
|
if (FD_ISSET (socket, & writeSet))
|
||||||
* condition |= ENET_SOCKET_WAIT_SEND;
|
* condition |= ENET_SOCKET_WAIT_SEND;
|
||||||
|
|
||||||
if (FD_ISSET (socket, & readSet))
|
if (FD_ISSET (socket, & readSet))
|
||||||
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
// // 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()
|
glm::vec3 ThirdPersonFollow::CalculatePosition()
|
||||||
|
|
|
@ -10,7 +10,6 @@ struct follow {
|
||||||
mfloat_t target_rot[4];
|
mfloat_t target_rot[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
mfloat_t *follow_calcpos();
|
|
||||||
mfloat_t *follow_calccenter();
|
mfloat_t *follow_calccenter();
|
||||||
mfloat_t *follow_postoffset();
|
mfloat_t *follow_postoffset();
|
||||||
mfloat_t *extentsoffset();
|
mfloat_t *extentsoffset();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct vec *vec_make(size_t width, int size)
|
||||||
struct vec *vec_make(int width, int size)
|
|
||||||
{
|
{
|
||||||
struct vec *new = calloc(1, sizeof(struct vec));
|
struct vec *new = calloc(1, sizeof(struct vec));
|
||||||
new->size = size;
|
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))
|
void vec_walk(struct vec *vec, void (*fn)(void *data))
|
||||||
{
|
{
|
||||||
for(int i = 0; i < vec->len; i++)
|
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)
|
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)
|
if (vec->size == vec->len)
|
||||||
vec_expand(vec);
|
vec_expand(vec);
|
||||||
|
@ -70,7 +71,7 @@ void *vec_add_sort(struct vec *vec, void *data,
|
||||||
while (sort(vec_p(vec, n), data))
|
while (sort(vec_p(vec, n), data))
|
||||||
n--;
|
n--;
|
||||||
|
|
||||||
vec_insert(vec, data, n);
|
return vec_insert(vec, data, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vec_insert(struct vec *vec, void *data, int n)
|
void *vec_insert(struct vec *vec, void *data, int n)
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
struct vec {
|
struct vec {
|
||||||
int len;
|
int len;
|
||||||
int size;
|
int size;
|
||||||
int width;
|
size_t width;
|
||||||
void *data;
|
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_get(struct vec *vec, int n);
|
||||||
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
||||||
void vec_clear(struct vec *vec);
|
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 */
|
/* sort returns 0 for a<=b, 1 for a>b */
|
||||||
void *vec_add_sort(struct vec *vec, void *data,
|
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_expand(struct vec *vec);
|
||||||
void vec_fit(struct vec *vec);
|
void vec_fit(struct vec *vec);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,62 +1,54 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#include "openglrender.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct mSDLWindow *window = NULL;
|
struct mSDLWindow *mainwin;
|
||||||
|
|
||||||
static struct mSDLWindow *windows[5];
|
static struct mSDLWindow *windows[5];
|
||||||
static int numWindows = 0;
|
static int numWindows = 0;
|
||||||
|
|
||||||
static SDL_GLContext publicGLContext = NULL;
|
|
||||||
|
|
||||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
|
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
|
||||||
w->width = width;
|
w->width = width;
|
||||||
w->height = height;
|
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) {
|
if (!w->window) {
|
||||||
YughLog(0, SDL_LOG_PRIORITY_ERROR,
|
printf("Couldn't make GLFW window\n");
|
||||||
"Window could not be created! SDL Error: %s",
|
|
||||||
SDL_GetError());
|
|
||||||
} else {
|
} else {
|
||||||
if (publicGLContext == NULL) {
|
glfwMakeContextCurrent(w->window);
|
||||||
publicGLContext = SDL_GL_CreateContext(w->window);
|
gladLoadGL(glfwGetProcAddress);
|
||||||
}
|
|
||||||
|
|
||||||
w->glContext = publicGLContext;
|
glfwSwapInterval(1);
|
||||||
SDL_GL_MakeCurrent(w->window, w->glContext);
|
|
||||||
|
|
||||||
|
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)
|
if (numWindows < 5)
|
||||||
windows[numWindows++] = w;
|
windows[numWindows++] = w;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainwin = windows[0];
|
||||||
return w;
|
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?
|
if (e->type == SDL_WINDOWEVENT && e->window.windowID == w->id) { // TODO: Check ptr direct?
|
||||||
switch (e->window.event) {
|
switch (e->window.event) {
|
||||||
case SDL_WINDOWEVENT_SHOWN:
|
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.",
|
"Changed size of window %d: width %d, height %d.",
|
||||||
w->id, w->width, w->height);
|
w->id, w->width, w->height);
|
||||||
window_makecurrent(w);
|
window_makecurrent(w);
|
||||||
/*w.projection =
|
w.projection =
|
||||||
glm::ortho(0.f, (float) width, 0.f, (float) height, -1.f,
|
glm::ortho(0.f, (float) width, 0.f, (float) height, -1.f,
|
||||||
1.f); */
|
1.f);
|
||||||
w->render = true;
|
w->render = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -134,18 +126,19 @@ void window_handle_event(struct mSDLWindow *w, SDL_Event * e)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_all_handle_events(SDL_Event *e)
|
void window_all_handle_events()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numWindows; i++) {
|
for (int i = 0; i < numWindows; i++) {
|
||||||
window_handle_event(windows[i], e);
|
window_handle_event(windows[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_makefullscreen(struct mSDLWindow *w)
|
void window_makefullscreen(struct mSDLWindow *w)
|
||||||
{
|
{
|
||||||
SDL_SetWindowFullscreen(w->window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
glfwMaximizeWindow(w->window);
|
||||||
w->fullscreen = true;
|
w->fullscreen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,31 +149,48 @@ void window_togglefullscreen(struct mSDLWindow *w)
|
||||||
if (w->fullscreen) {
|
if (w->fullscreen) {
|
||||||
window_makefullscreen(w);
|
window_makefullscreen(w);
|
||||||
} else {
|
} else {
|
||||||
SDL_SetWindowFullscreen(w->window, 0);
|
glfwRestoreWindow(w->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_makecurrent(struct mSDLWindow *w)
|
void window_makecurrent(struct mSDLWindow *w)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (w->window != SDL_GL_GetCurrentWindow())
|
if (w->window != SDL_GL_GetCurrentWindow())
|
||||||
SDL_GL_MakeCurrent(w->window, w->glContext);
|
SDL_GL_MakeCurrent(w->window, w->glContext);
|
||||||
glViewport(0, 0, w->width, w->height);
|
glViewport(0, 0, w->width, w->height);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_swap(struct mSDLWindow *w)
|
void window_swap(struct mSDLWindow *w)
|
||||||
{
|
{
|
||||||
SDL_GL_SwapWindow(w->window);
|
glfwSwapBuffers(w->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_seticon(struct mSDLWindow *w, struct Texture *icon)
|
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);
|
GLFWimage images[1];
|
||||||
SDL_FreeSurface(winIcon);
|
images[0] = load_icon(icon->path);
|
||||||
|
glfwSetWindowIcon(w->window, 1, images);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int window_hasfocus(struct mSDLWindow *w)
|
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
|
#ifndef WINDOW_H
|
||||||
#define WINDOW_H
|
#define WINDOW_H
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include "render.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
struct mSDLWindow {
|
struct mSDLWindow {
|
||||||
SDL_Window *window;
|
GLFWwindow *window;
|
||||||
SDL_GLContext glContext;
|
|
||||||
int id;
|
int id;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
@ -22,10 +22,15 @@ struct mSDLWindow {
|
||||||
|
|
||||||
struct Texture;
|
struct Texture;
|
||||||
|
|
||||||
|
extern struct mSDLWindow *mainwin;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
|
||||||
uint32_t flags);
|
uint32_t flags);
|
||||||
void window_handle_event(struct mSDLWindow *w, SDL_Event * e);
|
void window_destroy(struct mSDLWindow *w);
|
||||||
void window_all_handle_events(SDL_Event *e);
|
void window_handle_event(struct mSDLWindow *w);
|
||||||
|
void window_all_handle_events();
|
||||||
void window_makecurrent(struct mSDLWindow *w);
|
void window_makecurrent(struct mSDLWindow *w);
|
||||||
void window_makefullscreen(struct mSDLWindow *w);
|
void window_makefullscreen(struct mSDLWindow *w);
|
||||||
void window_togglefullscreen(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);
|
void window_seticon(struct mSDLWindow *w, struct Texture *icon);
|
||||||
int window_hasfocus(struct mSDLWindow *w);
|
int window_hasfocus(struct mSDLWindow *w);
|
||||||
|
|
||||||
|
double frame_time();
|
||||||
|
double elapsed_time();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <SDL2/SDL.h>
|
#include "render.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
@ -10,14 +10,11 @@
|
||||||
|
|
||||||
int physOn = 0;
|
int physOn = 0;
|
||||||
unsigned int frameCount = 0;
|
unsigned int frameCount = 0;
|
||||||
Uint32 lastTick = 0;
|
|
||||||
Uint32 frameTick = 0;
|
|
||||||
Uint32 elapsed = 0;
|
|
||||||
|
|
||||||
Uint32 physMS = FPS144;
|
double physMS = sFPS144;
|
||||||
Uint32 physlag = 0;
|
double physlag = 0;
|
||||||
Uint32 renderMS = FPS144;
|
double renderMS = sFPS144;
|
||||||
Uint32 renderlag = 0;
|
double renderlag = 0;
|
||||||
|
|
||||||
struct mCamera camera = {0};
|
struct mCamera camera = {0};
|
||||||
|
|
||||||
|
@ -27,63 +24,47 @@ int main(int argc, char **args)
|
||||||
|
|
||||||
engine_init();
|
engine_init();
|
||||||
|
|
||||||
struct mSDLWindow *window = MakeSDLWindow("Untitled Game", 1920, 1080,
|
struct mSDLWindow *window = MakeSDLWindow("Untitled Game", 1920, 1080, 0);
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
|
|
||||||
SDL_WINDOW_RESIZABLE);
|
|
||||||
|
|
||||||
|
|
||||||
openglInit();
|
openglInit();
|
||||||
|
|
||||||
|
|
||||||
editor_init(window);
|
editor_init(window);
|
||||||
|
|
||||||
|
|
||||||
int quit = 0;
|
int quit = 0;
|
||||||
SDL_Event e;
|
|
||||||
|
|
||||||
//While application is running
|
//While application is running
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
frameTick = SDL_GetTicks();
|
deltaT = elapsed_time();
|
||||||
elapsed = frameTick - lastTick;
|
|
||||||
lastTick = frameTick;
|
|
||||||
deltaT = elapsed / 1000.f;
|
|
||||||
|
|
||||||
physlag += elapsed;
|
physlag += deltaT;
|
||||||
renderlag += elapsed;
|
renderlag += deltaT;
|
||||||
|
|
||||||
input_poll();
|
input_poll();
|
||||||
|
|
||||||
if (physlag >= physMS) {
|
if (physlag >= physMS) {
|
||||||
phys2d_update(physMS / 1000.f);
|
phys2d_update(physMS);
|
||||||
|
|
||||||
physlag -= physMS;
|
physlag -= physMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (renderlag >= renderMS) {
|
if (renderlag >= renderMS) {
|
||||||
if (physOn) {
|
if (physOn) {
|
||||||
update_gameobjects();
|
update_gameobjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
camera_2d_update(&camera, renderMS);
|
||||||
camera_2d_update(&camera, renderMS / 1000.f);
|
|
||||||
|
|
||||||
openglRender(window, &camera);
|
openglRender(window, &camera);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
editor_render();
|
editor_render();
|
||||||
|
|
||||||
|
|
||||||
window_swap(window);
|
window_swap(window);
|
||||||
|
|
||||||
renderlag -= renderMS;
|
renderlag -= renderMS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
engine_stop();
|
engine_stop();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue