added half tile tilemaps and text rendering

This commit is contained in:
DaniTheSkunk 2023-01-22 17:47:53 +00:00
parent e1998aa111
commit 1a6edcd22a
7 changed files with 59 additions and 83 deletions

View File

@ -1,68 +0,0 @@
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0077 NEW)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/glfw-3.3.8)
set(PNG_BUILD_ZLIB ON)
set(PNG_SHARED OFF)
set(PNG_STATIC ON)
set(PNG_EXECUTABLES OFF)
set(PNG_TESTS OFF)
set(BUILD_SHARED_LIBS OFF)
set(SKIP_INSTALL_ALL ON)
set(ZLIB_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/zlib-1.2.13" "${CMAKE_BINARY_DIR}/lib/zlib-1.2.13")
add_subdirectory(lib/zlib-1.2.13)
#set(ZLIB_LIBRARY zlib)
add_subdirectory(lib/lpng1639)
project ("glew")
add_library(glew STATIC "lib/glew-2.1.0/src/glew.c" "lib/glew-2.1.0/include/GL/glew.h")
if(WIN32)
target_link_libraries(glew opengl32)
else()
target_link_libraries(glew GL)
endif()
target_include_directories(glew PRIVATE lib/glew-2.1.0/include)
set_target_properties(glew PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED YES C_EXTENSIONS YES)
set_target_properties(glew PROPERTIES COMPILE_FLAGS "-Wno-everything")
target_compile_definitions(glew PUBLIC GLEW_STATIC)
project ("skunkworks")
set(SOURCE
src/gl.h
src/skunkworks.c
src/skunkworks.h
src/test.c
src/vec2i.c
src/window.c
include/vec2i.h
include/window.h
)
add_executable (skunkworks ${SOURCE})
target_link_libraries(skunkworks glfw glew png_static zlibstatic)
target_include_directories(skunkworks PRIVATE
lib/glfw-3.8.8/include
lib/glew-2.1.0/include
lib/lpng1639
build/lib/lpng1639
include
)
set_target_properties(skunkworks PROPERTIES C_STANDARD 90 C_STANDARD_REQUIRED YES C_EXTENSIONS NO)
set_target_properties(skunkworks PROPERTIES COMPILE_FLAGS "-Wall -Werror -pedantic")
add_custom_command(TARGET skunkworks POST_BUILD
COMMAND $<$<CONFIG:release>:llvm-strip>
ARGS --strip-all $<TARGET_FILE:skunkworks>)

View File

@ -1,7 +1,9 @@
#include "gamepad.h" #include "gamepad.h"
#include "gsa_text.h"
#include <gsa.h> #include <gsa.h>
void init() { void init() {
i32 x, y; i32 x, y;
for(y = 0; y < 11; ++y) { for(y = 0; y < 11; ++y) {
@ -21,6 +23,12 @@ void init() {
maps[0].tiles[17][y + 1] = 0x1201; maps[0].tiles[17][y + 1] = 0x1201;
maps[0].tiles[18][y + 1] = 0x1202; maps[0].tiles[18][y + 1] = 0x1202;
} }
maps[1].half_tile = true;
/* maps[1].tiles[1][1] = gsa_get_char_tile(0x1010, 's'); */
font = 0x1010;
gsa_write_text(1, 7, 3, "Game Skunk Advance!!! <3");
} }
void tick() { void tick() {

View File

@ -22,6 +22,7 @@
#endif #endif
#include "gsa_input.h" #include "gsa_input.h"
#include "gsa_text.h"
#include "skunkworks.h" #include "skunkworks.h"
#include "vec2i.h" #include "vec2i.h"
#include "window.h" #include "window.h"
@ -39,6 +40,7 @@ struct gsa_map {
u16 tiles[TILEMAP_MAX_SIZE][TILEMAP_MAX_SIZE]; u16 tiles[TILEMAP_MAX_SIZE][TILEMAP_MAX_SIZE];
i32 w, h; i32 w, h;
i32 scrollx, scrolly; i32 scrollx, scrolly;
bool half_tile;
}; };
extern struct gsa_sprite sprites[MAX_SPRITES]; extern struct gsa_sprite sprites[MAX_SPRITES];

11
include/gsa_text.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef GUARD_B34FE9B65AE750F0DF88280BF07BA151
#define GUARD_B34FE9B65AE750F0DF88280BF07BA151
#include "types.h"
i16 gsa_get_char_tile(u8 ch);
void gsa_write_text(u8 map, u16 x, u16 y, char *str);
extern i16 font;
#endif /* GUARD_B34FE9B65AE750F0DF88280BF07BA151 */

View File

@ -47,6 +47,7 @@ skunk_sources = [
'src/gamepad.c', 'src/gamepad.c',
'src/gsa.c', 'src/gsa.c',
'src/gsa_input.c', 'src/gsa_input.c',
'src/gsa_text.c',
'src/image32.c', 'src/image32.c',
'src/image8.c', 'src/image8.c',
'src/scaler.c', 'src/scaler.c',

View File

@ -131,12 +131,13 @@ static void add_render_vert(f32 x, f32 y, f32 tx, f32 ty) {
++next_render_vert; ++next_render_vert;
} }
static void rect(f32 x, f32 y, f32 w, f32 h, i16 tile) { static void rect(f32 x, f32 y, f32 w, f32 h, i16 tile, bool half) {
f32 tx, ty, ts; f32 tx, ty, ts;
f32 tilesize = half ? 8.f : 16.f;
tx = ((tile % 256) * 16.f) / 4096.f; tx = ((tile % 256) * tilesize) / 4096.f;
ty = ((tile / 256) * 16.f) / 4096.f; ty = ((tile / 256) * tilesize) / 4096.f;
ts = 1.f / 256.f; ts = 1.f / (4096.f / tilesize);
if(next_render_vert >= MAX_RENDER_VERTS) { if(next_render_vert >= MAX_RENDER_VERTS) {
sw_error( sw_error(
@ -165,7 +166,7 @@ static void update_palette_gl() {
} }
void _gsa_tick() { void _gsa_tick() {
i32 i, x, y, startx, starty, endx, endy; i32 i, x, y, startx, starty, endx, endy, tcmult, tilesize;
_gsa_input_tick(); _gsa_input_tick();
@ -174,10 +175,12 @@ void _gsa_tick() {
next_render_vert = 0; next_render_vert = 0;
for(i = 0; i < MAX_TILEMAPS; ++i) { for(i = 0; i < MAX_TILEMAPS; ++i) {
startx = maps[i].scrollx / 16; tcmult = maps[i].half_tile ? 2 : 1;
starty = maps[i].scrolly / 16; tilesize = maps[i].half_tile ? 8 : 16;
endx = i32_min(TILEMAP_MAX_SIZE, startx + 20); startx = maps[i].scrollx / tilesize;
endy = i32_min(TILEMAP_MAX_SIZE, starty + 12); starty = maps[i].scrolly / tilesize;
endx = i32_min(TILEMAP_MAX_SIZE, startx + 20 * tcmult);
endy = i32_min(TILEMAP_MAX_SIZE, starty + 12 * tcmult);
startx = i32_max(0, startx); startx = i32_max(0, startx);
starty = i32_max(0, starty); starty = i32_max(0, starty);
@ -186,11 +189,12 @@ void _gsa_tick() {
u16 tile = maps[i].tiles[x][y]; u16 tile = maps[i].tiles[x][y];
if(tile) { if(tile) {
rect( rect(
x * 16 - maps[i].scrollx, x * tilesize - maps[i].scrollx,
y * 16 - maps[i].scrolly, y * tilesize - maps[i].scrolly,
16, tilesize,
16, tilesize,
tile tile,
maps[i].half_tile
); );
} }
} }
@ -199,7 +203,7 @@ void _gsa_tick() {
for(i = 0; i < MAX_SPRITES; ++i) { for(i = 0; i < MAX_SPRITES; ++i) {
if(sprites[i].tile > 0) { if(sprites[i].tile > 0) {
rect(sprites[i].x, sprites[i].y, 16, 16, sprites[i].tile); rect(sprites[i].x, sprites[i].y, 16, 16, sprites[i].tile, false);
} }
} }
glClearColor( glClearColor(

18
src/gsa_text.c Normal file
View File

@ -0,0 +1,18 @@
#include "gsa_text.h"
#define GSA_NOMAIN
#include "gsa.h"
i16 font;
i16 gsa_get_char_tile(u8 ch) {
return font + (ch % 0x10) + (ch / 0x10) * 0x100;
}
void gsa_write_text(u8 map, u16 x, u16 y, char *str) {
u8 *strp = (u8 *)str;
while(*strp) {
maps[map].tiles[x][y] = gsa_get_char_tile(*strp);
++strp;
++x;
}
}