Thu, 12 Jun 2025 22:44:49 +0200
consistent naming of structs and their typedefs
fixes #664
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * Copyright 2023 Mike Becker. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 | * POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
7 | 28 | #ifndef ASCENSION_CONTEXT_H |
29 | #define ASCENSION_CONTEXT_H | |
0 | 30 | |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
31 | #include "datatypes.h" |
7 | 32 | #include "window.h" |
63
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
33 | #include "input.h" |
48 | 34 | #include "ui/font.h" |
7 | 35 | |
0 | 36 | #include <cx/buffer.h> |
86
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
37 | #include <cx/string.h> |
0 | 38 | |
95
622887f7e954
in preparation of more scenes, bring back AscScene struct
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
39 | #include <stdio.h> |
622887f7e954
in preparation of more scenes, bring back AscScene struct
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
40 | |
0 | 41 | /** The flag for the overall initialized state. */ |
42 | #define ASC_FLAG_INITILIZED 0x01u | |
43 | ||
83
f7ce0db6f72b
implement view matrix in sprite shader
Mike Becker <universe@uap-core.de>
parents:
80
diff
changeset
|
44 | /** Flag is set when the error buffer contains new error information. */ |
0 | 45 | #define ASC_FLAG_HAS_ERROR 0x02u |
46 | ||
80 | 47 | /** Flag is set when SDL wants to quit the application. */ |
0 | 48 | #define ASC_FLAG_QUIT 0x80000000u |
49 | ||
7 | 50 | /** |
51 | * The global ascension context. | |
52 | */ | |
145
a3231310d66d
consistent naming of structs and their typedefs
Mike Becker <universe@uap-core.de>
parents:
132
diff
changeset
|
53 | typedef struct asc_context_s { |
7 | 54 | unsigned int flags; |
0 | 55 | CxBuffer error_buffer; |
86
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
56 | cxmutstr font_path; |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
57 | cxmutstr shader_path; |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
58 | cxmutstr texture_path; |
63
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
59 | AscInput input; |
7 | 60 | AscWindow windows[ASC_MAX_WINDOWS]; |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
61 | AscFont active_font; |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
62 | unsigned char active_window; |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
63 | asc_col4i ink; |
128 | 64 | float ui_scale; |
46
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
65 | uint64_t frame_nanos; |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
66 | uint64_t total_nanos; |
0 | 67 | } AscContext; |
68 | ||
69 | /** Global ascension context. */ | |
70 | extern AscContext asc_context; | |
71 | ||
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
72 | /** |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
73 | * The currently active font. |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
74 | * @see asc_font() |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
75 | */ |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
76 | #define asc_active_font asc_context.active_font |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
77 | |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
78 | #ifdef NDEBUG |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
79 | /** |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
80 | * The currently active window in the context. |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
81 | * @see asc_window_activate() |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
82 | */ |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
83 | #define asc_active_window \ |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
84 | (&asc_context.windows[asc_context.active_window]) |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
85 | #else |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
86 | /** |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
87 | * The currently active window in the context. |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
88 | * @see asc_window_activate() |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
89 | */ |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
90 | #define asc_active_window asc_active_window_assert() |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
91 | AscWindow *asc_active_window_assert(void); |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
92 | #endif // NDEBUG |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
93 | |
0 | 94 | void asc_context_initialize(void); |
95 | void asc_context_destroy(void); | |
96 | ||
63
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
97 | /** |
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
98 | * Signals the context that we want to quit the application. |
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
99 | */ |
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
100 | void asc_context_quit(void); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
101 | |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
102 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
103 | * Dispatches events and synchronizes all initialized windows. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
104 | * |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
105 | * @return false, if the application wants to quit, true otherwise |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
106 | */ |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
107 | bool asc_loop_next(void); |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
108 | |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
109 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
110 | * Sets the active drawing color. |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
111 | */ |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
112 | #define asc_ink(color) asc_context.ink = (color) |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
113 | #define asc_ink_rgba(r,g,b,a) asc_context.ink = (asc_col4i){(r),(g),(b),(a)} |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
114 | #define asc_ink_rgb(r,g,b) asc_context.ink = (asc_col4i){(r),(g),(b),255u} |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
115 | |
86
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
116 | void asc_set_font_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
117 | void asc_set_shader_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
118 | void asc_set_texture_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
119 | |
7 | 120 | #endif /* ASCENSION_CONTEXT_H */ |
0 | 121 |