add datatypes.h

Mon, 30 Oct 2023 18:09:27 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 30 Oct 2023 18:09:27 +0100
changeset 3
1efd6da2ad53
parent 2
bb2bfff31f1d
child 4
b7acda6a4476

add datatypes.h

src/Makefile file | annotate | diff | comparison | revisions
src/ascension/core.h file | annotate | diff | comparison | revisions
src/ascension/datatypes.h file | annotate | diff | comparison | revisions
src/core.c file | annotate | diff | comparison | revisions
test/sandbox.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/Makefile	Mon Oct 30 17:59:37 2023 +0100
     1.2 +++ b/src/Makefile	Mon Oct 30 18:09:27 2023 +0100
     1.3 @@ -40,7 +40,8 @@
     1.4  
     1.5  FORCE:
     1.6  
     1.7 -$(BUILD_DIR)/core.o: core.c ascension/core.h ascension/utils.h
     1.8 +$(BUILD_DIR)/core.o: core.c ascension/core.h ascension/datatypes.h \
     1.9 + ascension/utils.h
    1.10  	echo "Compiling $<"
    1.11  	$(CC) -o $@ $(CFLAGS) -c $<
    1.12  
     2.1 --- a/src/ascension/core.h	Mon Oct 30 17:59:37 2023 +0100
     2.2 +++ b/src/ascension/core.h	Mon Oct 30 18:09:27 2023 +0100
     2.3 @@ -36,6 +36,8 @@
     2.4  #include <cx/buffer.h>
     2.5  #include <cx/list.h>
     2.6  
     2.7 +#include "datatypes.h"
     2.8 +
     2.9  #ifdef __cplusplus
    2.10  extern "C" {
    2.11  #endif
    2.12 @@ -61,8 +63,7 @@
    2.13  typedef struct AscWindowSettings {
    2.14      int depth_size;
    2.15      int vsync;
    2.16 -    int width;
    2.17 -    int height;
    2.18 +    asc_vec2i dimensions;
    2.19      int fullscreen;
    2.20      int gl_major_version;
    2.21      int gl_minor_version;
    2.22 @@ -73,8 +74,7 @@
    2.23      SDL_Window* window;
    2.24      SDL_GLContext glctx;
    2.25      Uint32 id;
    2.26 -    int width;
    2.27 -    int height;
    2.28 +    asc_vec2i dimensions;
    2.29  } AscWindow;
    2.30  
    2.31  void asc_context_initialize(void);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/ascension/datatypes.h	Mon Oct 30 18:09:27 2023 +0100
     3.3 @@ -0,0 +1,46 @@
     3.4 +/*
     3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 + * Copyright 2023 Mike Becker. All rights reserved.
     3.7 + *
     3.8 + * Redistribution and use in source and binary forms, with or without
     3.9 + * modification, are permitted provided that the following conditions are met:
    3.10 + *
    3.11 + *   1. Redistributions of source code must retain the above copyright
    3.12 + *      notice, this list of conditions and the following disclaimer.
    3.13 + *
    3.14 + *   2. Redistributions in binary form must reproduce the above copyright
    3.15 + *      notice, this list of conditions and the following disclaimer in the
    3.16 + *      documentation and/or other materials provided with the distribution.
    3.17 + *
    3.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    3.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    3.22 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    3.23 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    3.24 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    3.25 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    3.26 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    3.27 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    3.28 + * POSSIBILITY OF SUCH DAMAGE.
    3.29 + */
    3.30 +
    3.31 +#ifndef ASCENSION_DATATYPES_H
    3.32 +#define ASCENSION_DATATYPES_H
    3.33 +
    3.34 +#ifdef __cplusplus
    3.35 +extern "C" {
    3.36 +#endif
    3.37 +
    3.38 +typedef union {
    3.39 +    int data[2];
    3.40 +    struct { int x, y; };
    3.41 +    struct { int width, height; };
    3.42 +} asc_vec2i;
    3.43 +
    3.44 +
    3.45 +#ifdef __cplusplus
    3.46 +} // extern "C"
    3.47 +#endif
    3.48 +
    3.49 +#endif //ASCENSION_DATATYPES_H
     4.1 --- a/src/core.c	Mon Oct 30 17:59:37 2023 +0100
     4.2 +++ b/src/core.c	Mon Oct 30 18:09:27 2023 +0100
     4.3 @@ -142,8 +142,8 @@
     4.4      CxIterator iter = cxListIterator(asc_context.windows);
     4.5      cx_foreach(AscWindow*, w, iter) {
     4.6          if (w->id == id) {
     4.7 -            w->width = width;
     4.8 -            w->height = height;
     4.9 +            w->dimensions.width = width;
    4.10 +            w->dimensions.height = height;
    4.11              return;
    4.12          }
    4.13      }
    4.14 @@ -186,8 +186,8 @@
    4.15  void asc_window_settings_init_defaults(AscWindowSettings* settings) {
    4.16      settings->depth_size = 24;
    4.17      settings->vsync = 1;
    4.18 -    settings->width = 800;
    4.19 -    settings->height = 600;
    4.20 +    settings->dimensions.width = 800;
    4.21 +    settings->dimensions.height = 600;
    4.22      settings->fullscreen = 0;
    4.23      settings->gl_major_version = 3;
    4.24      settings->gl_minor_version = 3;
    4.25 @@ -202,8 +202,8 @@
    4.26              settings->title,
    4.27              SDL_WINDOWPOS_CENTERED,
    4.28              SDL_WINDOWPOS_CENTERED,
    4.29 -            settings->width,
    4.30 -            settings->height,
    4.31 +            settings->dimensions.width,
    4.32 +            settings->dimensions.height,
    4.33              flags
    4.34      );
    4.35      if (window->window == NULL) {
    4.36 @@ -212,7 +212,10 @@
    4.37      }
    4.38  
    4.39      window->id = SDL_GetWindowID(window->window);
    4.40 -    SDL_GetWindowSize(window->window, &window->width, &window->height);
    4.41 +    SDL_GetWindowSize(window->window,
    4.42 +            &window->dimensions.width,
    4.43 +            &window->dimensions.height
    4.44 +    );
    4.45  
    4.46      SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    4.47      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version);
    4.48 @@ -280,7 +283,7 @@
    4.49  void asc_window_sync(AscWindow const* window) {
    4.50      SDL_GL_MakeCurrent(window->window, window->glctx);
    4.51      SDL_GL_SwapWindow(window->window);
    4.52 -    glViewport(0, 0, window->width, window->height);
    4.53 +    glViewport(0, 0, window->dimensions.width, window->dimensions.height);
    4.54      glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    4.55      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4.56  }
     5.1 --- a/test/sandbox.c	Mon Oct 30 17:59:37 2023 +0100
     5.2 +++ b/test/sandbox.c	Mon Oct 30 18:09:27 2023 +0100
     5.3 @@ -27,8 +27,6 @@
     5.4  
     5.5  #include "ascension/core.h"
     5.6  
     5.7 -#include <unistd.h>
     5.8 -
     5.9  static bool show_message_box_on_error(SDL_Window* window) {
    5.10      if (asc_has_error()) {
    5.11          SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,

mercurial