# HG changeset patch # User Mike Becker # Date 1698685767 -3600 # Node ID 1efd6da2ad5306e04302f036461e861431bf05a3 # Parent bb2bfff31f1dd169ef6a037776b9c16d3491982b add datatypes.h diff -r bb2bfff31f1d -r 1efd6da2ad53 src/Makefile --- a/src/Makefile Mon Oct 30 17:59:37 2023 +0100 +++ b/src/Makefile Mon Oct 30 18:09:27 2023 +0100 @@ -40,7 +40,8 @@ FORCE: -$(BUILD_DIR)/core.o: core.c ascension/core.h ascension/utils.h +$(BUILD_DIR)/core.o: core.c ascension/core.h ascension/datatypes.h \ + ascension/utils.h echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< diff -r bb2bfff31f1d -r 1efd6da2ad53 src/ascension/core.h --- a/src/ascension/core.h Mon Oct 30 17:59:37 2023 +0100 +++ b/src/ascension/core.h Mon Oct 30 18:09:27 2023 +0100 @@ -36,6 +36,8 @@ #include #include +#include "datatypes.h" + #ifdef __cplusplus extern "C" { #endif @@ -61,8 +63,7 @@ typedef struct AscWindowSettings { int depth_size; int vsync; - int width; - int height; + asc_vec2i dimensions; int fullscreen; int gl_major_version; int gl_minor_version; @@ -73,8 +74,7 @@ SDL_Window* window; SDL_GLContext glctx; Uint32 id; - int width; - int height; + asc_vec2i dimensions; } AscWindow; void asc_context_initialize(void); diff -r bb2bfff31f1d -r 1efd6da2ad53 src/ascension/datatypes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ascension/datatypes.h Mon Oct 30 18:09:27 2023 +0100 @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * Copyright 2023 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ASCENSION_DATATYPES_H +#define ASCENSION_DATATYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef union { + int data[2]; + struct { int x, y; }; + struct { int width, height; }; +} asc_vec2i; + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif //ASCENSION_DATATYPES_H diff -r bb2bfff31f1d -r 1efd6da2ad53 src/core.c --- a/src/core.c Mon Oct 30 17:59:37 2023 +0100 +++ b/src/core.c Mon Oct 30 18:09:27 2023 +0100 @@ -142,8 +142,8 @@ CxIterator iter = cxListIterator(asc_context.windows); cx_foreach(AscWindow*, w, iter) { if (w->id == id) { - w->width = width; - w->height = height; + w->dimensions.width = width; + w->dimensions.height = height; return; } } @@ -186,8 +186,8 @@ void asc_window_settings_init_defaults(AscWindowSettings* settings) { settings->depth_size = 24; settings->vsync = 1; - settings->width = 800; - settings->height = 600; + settings->dimensions.width = 800; + settings->dimensions.height = 600; settings->fullscreen = 0; settings->gl_major_version = 3; settings->gl_minor_version = 3; @@ -202,8 +202,8 @@ settings->title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - settings->width, - settings->height, + settings->dimensions.width, + settings->dimensions.height, flags ); if (window->window == NULL) { @@ -212,7 +212,10 @@ } window->id = SDL_GetWindowID(window->window); - SDL_GetWindowSize(window->window, &window->width, &window->height); + SDL_GetWindowSize(window->window, + &window->dimensions.width, + &window->dimensions.height + ); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version); @@ -280,7 +283,7 @@ void asc_window_sync(AscWindow const* window) { SDL_GL_MakeCurrent(window->window, window->glctx); SDL_GL_SwapWindow(window->window); - glViewport(0, 0, window->width, window->height); + glViewport(0, 0, window->dimensions.width, window->dimensions.height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff -r bb2bfff31f1d -r 1efd6da2ad53 test/sandbox.c --- a/test/sandbox.c Mon Oct 30 17:59:37 2023 +0100 +++ b/test/sandbox.c Mon Oct 30 18:09:27 2023 +0100 @@ -27,8 +27,6 @@ #include "ascension/core.h" -#include - static bool show_message_box_on_error(SDL_Window* window) { if (asc_has_error()) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,