input and handler possibly fixed
This commit is contained in:
parent
31b8730a61
commit
d6281e8eac
11 changed files with 84 additions and 59 deletions
|
|
@ -4,76 +4,101 @@
|
|||
#include "arc/engine/state.h"
|
||||
#include "arc/graphics/window.h"
|
||||
#include "arc/graphics/renderer.h"
|
||||
#include "arc/input/mouse.h"
|
||||
#include "arc/input/keyboard.h"
|
||||
#include "arc/std/errno.h"
|
||||
#include "arc/std/handler.h"
|
||||
|
||||
//NOTE: this is very temp, mostly to get smthn running so I can test out different ideas
|
||||
//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas
|
||||
#ifdef ARC_SDL
|
||||
#include <SDL.h>
|
||||
#include "arc/graphics/sdl/window.h"
|
||||
#include "arc/graphics/sdl/renderer.h"
|
||||
#include "arc/input/sdl/mouse.h"
|
||||
#include "arc/input/sdl/keyboard.h"
|
||||
#endif // ARC_SDL
|
||||
|
||||
void ARC_EngineData_Create(ARC_EngineData **data){
|
||||
*data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData));
|
||||
(*data)->window = NULL;
|
||||
(*data)->renderer = NULL;
|
||||
(*data)->mouse = NULL;
|
||||
|
||||
ARC_Handler_Create(&((*data)->state), sizeof(ARC_State));
|
||||
|
||||
ARC_WindowInfo windowInfo;
|
||||
ARC_RenderInfo renderInfo;
|
||||
ARC_WindowInfo windowInfo;
|
||||
ARC_RenderInfo renderInfo;
|
||||
ARC_MouseInfo mouseInfo;
|
||||
ARC_KeyboardInfo keyboardInfo;
|
||||
|
||||
#ifdef ARC_SDL
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0){
|
||||
printf("Error: initializing SDL\nSDL Error: %s\n", SDL_GetError());
|
||||
free(*data);
|
||||
return;
|
||||
}
|
||||
|
||||
windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 720, 480, 0 };
|
||||
windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 2560, 1440, 0 };
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Window_Create(&((*data)->window), &windowInfo);
|
||||
//TODO: handle arc_errno errors here
|
||||
if(arc_errno){
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ARC_SDL
|
||||
renderInfo = (ARC_RenderInfo){ (SDL_Window *)(*data)->window->window, -1, SDL_RENDERER_ACCELERATED };
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Renderer_Create(&((*data)->renderer), &renderInfo);
|
||||
//TODO: handle arc_errno errors here
|
||||
if(arc_errno){
|
||||
ARC_Window_Destroy((*data)->window);
|
||||
free(data);
|
||||
}
|
||||
|
||||
#ifdef ARC_SDL
|
||||
SDL_Event *event = (SDL_Event *)malloc(sizeof(SDL_Event));
|
||||
mouseInfo = (ARC_MouseInfo ){ event };
|
||||
keyboardInfo = (ARC_KeyboardInfo){ event };
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Mouse_Create(&((*data)->mouse), &mouseInfo);
|
||||
|
||||
ARC_Keyboard_Create(&((*data)->keyboard), &keyboardInfo);
|
||||
}
|
||||
|
||||
void ARC_EngineData_Destroy(ARC_EngineData *data){
|
||||
#ifdef ARC_SDL
|
||||
ARC_Handler_Destroy(data->state, NULL); //TODO: replace null with cleanup function
|
||||
free(data->mouse->event);
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Mouse_Destroy(data->mouse);
|
||||
ARC_Renderer_Destroy(data->renderer);
|
||||
ARC_Window_Destroy(data->window);
|
||||
#endif // ARC_SDL
|
||||
ARC_Handler_Destroy(data->state, NULL); //TODO: replace null with cleanup function
|
||||
}
|
||||
|
||||
void ARC_Engine_Run(ARC_EngineData *data){
|
||||
double lastTime = 0, currentTime;
|
||||
if(arc_errno){
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ARC_SDL
|
||||
SDL_Event event;
|
||||
SDL_Event *event = data->mouse->event;
|
||||
#endif // ARC_SDL
|
||||
|
||||
double lastTime = 0, currentTime;
|
||||
|
||||
while(1){
|
||||
#ifdef ARC_SDL
|
||||
currentTime = SDL_GetTicks();
|
||||
data->dt = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
|
||||
while(SDL_PollEvent(&event)){
|
||||
if(event.type == SDL_QUIT){ return; }
|
||||
if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE){ return; }
|
||||
}
|
||||
SDL_PollEvent(data->mouse->event);
|
||||
if(event->type == SDL_QUIT){ return; }
|
||||
if(event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_ESCAPE){ return; }
|
||||
#endif // ARC_SDL
|
||||
|
||||
// data->mouse.update(data->event);
|
||||
// data->keyboard.update(data->event);
|
||||
ARC_Mouse_Update(data->mouse);
|
||||
|
||||
ARC_Keyboard_Update(data->keyboard);
|
||||
|
||||
// data->state.update();
|
||||
ARC_Handler_Iterate(data->state, ARC_State_Update);
|
||||
|
||||
ARC_Renderer_Clear(data->renderer);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
#include "arc/engine/state.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void ARC_State_Update(void *data){
|
||||
ARC_State *temp = (ARC_State *) data;
|
||||
((ARC_State *)data)->updateFn();
|
||||
((ARC_State *)data)->updateFn(((ARC_State *)data)->data);
|
||||
}
|
||||
|
||||
void ARC_State_Render(void *data){
|
||||
ARC_State *temp = (ARC_State *) data;
|
||||
((ARC_State *)data)->renderFn();
|
||||
((ARC_State *)data)->renderFn(((ARC_State *)data)->data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue