fix mixing up of SDL and libc allocators, proper flushing of quad build buffers
This commit is contained in:
		@@ -12,7 +12,7 @@
 | 
			
		||||
void game_tick(void) {
 | 
			
		||||
    if (ctx.initialization_needed) {
 | 
			
		||||
        if (!ctx.udata) {
 | 
			
		||||
            ctx.udata = ccalloc(1, sizeof (State));
 | 
			
		||||
            ctx.udata = calloc(1, sizeof (State));
 | 
			
		||||
 | 
			
		||||
            State *state = ctx.udata;
 | 
			
		||||
            state->ctx = &ctx;
 | 
			
		||||
 
 | 
			
		||||
@@ -203,7 +203,7 @@ static void calc_collisions_y(Player *player) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Player *player_create(World *world) {
 | 
			
		||||
    Player *player = cmalloc(sizeof *player);
 | 
			
		||||
    Player *player = malloc(sizeof *player);
 | 
			
		||||
 | 
			
		||||
    *player = (Player) {
 | 
			
		||||
        .world = world,
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ static void ingame_end(State *state) {
 | 
			
		||||
Scene *ingame_scene(State *state) {
 | 
			
		||||
    (void)state;
 | 
			
		||||
 | 
			
		||||
    SceneIngame *new_scene = ccalloc(1, sizeof *new_scene);
 | 
			
		||||
    SceneIngame *new_scene = calloc(1, sizeof *new_scene);
 | 
			
		||||
    new_scene->base.tick = ingame_tick;
 | 
			
		||||
    new_scene->base.end = ingame_end;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,8 @@
 | 
			
		||||
 | 
			
		||||
#include "twn_game_api.h"
 | 
			
		||||
 | 
			
		||||
#include <SDL2/SDL.h>
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void title_tick(State *state) {
 | 
			
		||||
@@ -26,8 +25,9 @@ static void title_tick(State *state) {
 | 
			
		||||
    
 | 
			
		||||
    /* draw the tick count as an example of dynamic text */
 | 
			
		||||
    size_t text_str_len = snprintf(NULL, 0, "%llu", (unsigned long long)state->ctx->frame_number) + 1;
 | 
			
		||||
    char *text_str = cmalloc(text_str_len);
 | 
			
		||||
    char *text_str = malloc(text_str_len);
 | 
			
		||||
    snprintf(text_str, text_str_len, "%llu", (unsigned long long)state->ctx->frame_number);
 | 
			
		||||
    free(text_str);
 | 
			
		||||
 | 
			
		||||
    const char *font = "fonts/kenney-pixel.ttf";
 | 
			
		||||
    float text_h = 32;
 | 
			
		||||
@@ -64,7 +64,7 @@ static void title_end(State *state) {
 | 
			
		||||
Scene *title_scene(State *state) {
 | 
			
		||||
    (void)state;
 | 
			
		||||
 | 
			
		||||
    SceneTitle *new_scene = ccalloc(1, sizeof *new_scene);
 | 
			
		||||
    SceneTitle *new_scene = calloc(1, sizeof *new_scene);
 | 
			
		||||
    new_scene->base.tick = title_tick;
 | 
			
		||||
    new_scene->base.end = title_end;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -45,7 +45,7 @@ static void drawdef_debug(struct World *world) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct World *world_create(void) {
 | 
			
		||||
    struct World *world = cmalloc(sizeof *world);
 | 
			
		||||
    struct World *world = malloc(sizeof *world);
 | 
			
		||||
 | 
			
		||||
    *world = (struct World) {
 | 
			
		||||
        .tiles = NULL,
 | 
			
		||||
@@ -58,9 +58,9 @@ struct World *world_create(void) {
 | 
			
		||||
    /* create the tilemap */
 | 
			
		||||
    /* it simply stores what's in each tile as a 2d array */
 | 
			
		||||
    /* on its own, it's entirely unrelated to drawing or logic */
 | 
			
		||||
    world->tilemap = cmalloc(sizeof *world->tilemap * world->tilemap_height);
 | 
			
		||||
    world->tilemap = malloc(sizeof *world->tilemap * world->tilemap_height);
 | 
			
		||||
    for (size_t i = 0; i < world->tilemap_height; ++i) {
 | 
			
		||||
        world->tilemap[i] = cmalloc(sizeof **world->tilemap * world->tilemap_width);
 | 
			
		||||
        world->tilemap[i] = malloc(sizeof **world->tilemap * world->tilemap_width);
 | 
			
		||||
 | 
			
		||||
        for (size_t j = 0; j < world->tilemap_width; ++j) {
 | 
			
		||||
            world->tilemap[i][j] = TILE_TYPE_VOID;
 | 
			
		||||
@@ -81,7 +81,7 @@ struct World *world_create(void) {
 | 
			
		||||
    /* the tiles array contains data meant to be used by other logic */
 | 
			
		||||
    /* most importantly, it is used to draw the tiles */
 | 
			
		||||
    const size_t tile_count = world->tilemap_height * world->tilemap_width;
 | 
			
		||||
    world->tiles = cmalloc(sizeof *world->tiles * tile_count);
 | 
			
		||||
    world->tiles = malloc(sizeof *world->tiles * tile_count);
 | 
			
		||||
    update_tiles(world);
 | 
			
		||||
 | 
			
		||||
    return world;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user