prosperon/source/engine/engine.c

79 lines
1.6 KiB
C
Raw Normal View History

2022-01-19 16:43:21 -06:00
#include "engine.h"
2021-11-30 21:29:18 -06:00
#ifdef EDITOR
#include "editor.h"
#endif
2022-01-19 16:43:21 -06:00
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
2021-11-30 21:29:18 -06:00
#include "openglrender.h"
#include "window.h"
#include "camera.h"
#include "input.h"
#include "sprite.h"
#include "2dphysics.h"
#include "gameobject.h"
#include "registry.h"
2022-01-19 16:43:21 -06:00
#include "log.h"
#include "resources.h"
2021-11-30 21:29:18 -06:00
unsigned int frameCount = 0;
2022-01-19 16:43:21 -06:00
uint32_t lastTick = 0;
uint32_t frameTick = 0;
uint32_t elapsed = 0;
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
uint32_t physMS = FPS144;
uint32_t physlag = 0;
uint32_t renderMS = FPS144;
uint32_t renderlag = 0;
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
// TODO: Init on the heap
struct mCamera camera = {0};
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
#include "engine.h"
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
void engine_init()
2021-11-30 21:29:18 -06:00
{
2022-01-19 16:43:21 -06:00
//Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
YughLog(0, SDL_LOG_PRIORITY_ERROR,
"SDL could not initialize! SDL Error: %s", SDL_GetError());
}
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
//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);
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); /* How many x MSAA */
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
2022-02-01 14:50:25 -06:00
resources_init();
script_init();
2022-01-19 16:43:21 -06:00
registry_init();
init_gameobjects();
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
prefabs = vec_make(MAXNAME, 25);
camera.speed = 500;
stbi_set_flip_vertically_on_load(1);
2021-11-30 21:29:18 -06:00
phys2d_init();
2022-01-19 16:43:21 -06:00
gui_init();
sound_init();
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
}
2021-11-30 21:29:18 -06:00
2022-01-19 16:43:21 -06:00
void engine_stop()
{
2021-11-30 21:29:18 -06:00
SDL_StopTextInput();
SDL_Quit();
2022-01-19 16:43:21 -06:00
}