You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
84 lines
2.1 KiB
|
|
#include <SDL2/SDL.h> |
|
#include <glm/glm.hpp> |
|
|
|
#include "camera.h" |
|
#include "dumbLog.h" |
|
#include "renderer.h" |
|
#include "entity.h" |
|
|
|
|
|
typedef void (*frame_callback_fn) (render_state*); |
|
|
|
void |
|
doFrameCallback(render_state* rs) |
|
{ |
|
} |
|
|
|
void |
|
doRenderLoop(render_state* rs, frame_callback_fn callback_fn, Entity* entities, uint entity_count) |
|
{ |
|
// TODO: move frame delay to renderFrame() |
|
const uint TARGET_FPS = 60; |
|
const uint FRAME_DELAY = 1000 / TARGET_FPS; |
|
uint frameStart, frameTime; |
|
bool running = true; |
|
SDL_Event e; |
|
|
|
while (running) { |
|
frameStart = SDL_GetTicks(); |
|
|
|
// TODO: add a better structure for input, and provide a callback to use here |
|
while (SDL_PollEvent(&e)) { |
|
if ((e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) |
|
|| e.type == SDL_QUIT) { |
|
running = false; |
|
} |
|
} |
|
|
|
callback_fn(rs); |
|
// TODO: entity pointer and entity count should be stored somewhere on the render_state object |
|
renRenderFrame(rs, entities, entity_count); |
|
SDL_GL_SwapWindow(rs->handles.window); |
|
frameTime = SDL_GetTicks() - frameStart; |
|
|
|
if (FRAME_DELAY > frameTime) |
|
SDL_Delay(FRAME_DELAY - frameTime); |
|
} |
|
} |
|
|
|
int |
|
main() |
|
{ |
|
render_state* rs = renInit(); |
|
|
|
meInitAssimp(); |
|
|
|
// TODO: entInit() doesn't allocate memory because we want to do the allocation in |
|
// one big block, but this is really clunky to use |
|
Entity spaceship; |
|
|
|
// TODO: this should be handled in entInit |
|
// TODO: utilCopyCStr() can fail, and returns false |
|
utilCopyCStr(spaceship.model_filename, "../data/spaceship.glb", 256); |
|
entSetWorldPosition(spaceship, 0, 0, 0); |
|
|
|
// set entity scale, rotation, world_transform to defaults :( ... |
|
|
|
// need to finish loading binary texture data in mesh::loadDiffuseTexture() |
|
|
|
// setup camera |
|
glm::vec3 cam_pos(0, -100, 100); |
|
cameraInitPerspective(rs->cam, cam_pos, spaceship.translation, rs->cam.world_up); |
|
|
|
if (entInit(spaceship, "../data", rs->default_shader)) { |
|
doRenderLoop(rs, doFrameCallback, &spaceship, 1); |
|
} else { |
|
LOG(Error) << "Error initializing entity, exiting\n"; |
|
} |
|
|
|
|
|
// TODO: way more cleanup to do :(, see hexgame::cleanUp() |
|
meShutdownAssimp(); |
|
return 0; |
|
}
|
|
|