Sat, 19 Apr 2025 15:06:24 +0200
make asset paths configurable
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 | |
39 | /** The flag for the overall initialized state. */ | |
40 | #define ASC_FLAG_INITILIZED 0x01u | |
41 | ||
83
f7ce0db6f72b
implement view matrix in sprite shader
Mike Becker <universe@uap-core.de>
parents:
80
diff
changeset
|
42 | /** Flag is set when the error buffer contains new error information. */ |
0 | 43 | #define ASC_FLAG_HAS_ERROR 0x02u |
44 | ||
80 | 45 | /** Flag is set when SDL wants to quit the application. */ |
0 | 46 | #define ASC_FLAG_QUIT 0x80000000u |
47 | ||
7 | 48 | /** |
49 | * The global ascension context. | |
50 | */ | |
0 | 51 | typedef struct AscContext { |
7 | 52 | unsigned int flags; |
0 | 53 | CxBuffer error_buffer; |
86
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
54 | cxmutstr font_path; |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
55 | cxmutstr shader_path; |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
56 | cxmutstr texture_path; |
63
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
57 | AscInput input; |
7 | 58 | 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
|
59 | AscFont active_font; |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
60 | unsigned char fonts_loaded; |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
61 | unsigned char active_window; |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
62 | asc_col4i ink; |
46
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
63 | uint64_t frame_nanos; |
d3285aed65b3
make the timer have nanoseconds precision
Mike Becker <universe@uap-core.de>
parents:
33
diff
changeset
|
64 | uint64_t total_nanos; |
0 | 65 | } AscContext; |
66 | ||
67 | /** Global ascension context. */ | |
68 | extern AscContext asc_context; | |
69 | ||
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
70 | /** |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
71 | * The currently active font. |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
72 | * @see asc_font() |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
73 | */ |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
74 | #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
|
75 | |
66
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
76 | #ifdef NDEBUG |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
77 | /** |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
78 | * 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
|
79 | * @see asc_window_activate() |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
80 | */ |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
81 | #define asc_active_window \ |
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
82 | (&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
|
83 | #else |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
84 | /** |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
85 | * 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
|
86 | * @see asc_window_activate() |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
87 | */ |
8297afa1c29c
replaces broken font cache with improved cache - fixes #387
Mike Becker <universe@uap-core.de>
parents:
65
diff
changeset
|
88 | #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
|
89 | 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
|
90 | #endif // NDEBUG |
65
9c44c55d327a
consistently refer to windows by ID - fixes #381
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
91 | |
0 | 92 | void asc_context_initialize(void); |
93 | void asc_context_destroy(void); | |
94 | ||
63
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
95 | /** |
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
96 | * 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
|
97 | */ |
e3cacdd636e4
implement mouse motion and key press events
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
98 | void asc_context_quit(void); |
16
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
99 | |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
100 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
101 | * 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
|
102 | * |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
103 | * @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
|
104 | */ |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
105 | bool asc_loop_next(void); |
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 | /** |
c5dde81b6fb2
add text rendering and demo FPS counter
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
108 | * Sets the active drawing color. |
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 | #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
|
111 | #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
|
112 | #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
|
113 | |
86
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
114 | |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
115 | void asc_set_font_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
116 | void asc_set_shader_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
117 | void asc_set_texture_path(const char *path); |
943bf9d7c6d6
make asset paths configurable
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
118 | |
7 | 119 | #endif /* ASCENSION_CONTEXT_H */ |
0 | 120 |