refs: nuke from orbit
This commit is contained in:
parent
837d3bff39
commit
76bd4d88b2
7 changed files with 0 additions and 144 deletions
|
@ -93,7 +93,6 @@ void ent_unregister(EntityInterface *ent) {
|
|||
assert(dynarray_get(&entities.registered, ent->index) == ent);
|
||||
EntityInterface *sub = entities.registered.data[--entities.registered.num_elements];
|
||||
entities.registered.data[sub->index = ent->index] = sub;
|
||||
del_ref(ent);
|
||||
}
|
||||
|
||||
static int ent_cmp(const void *ptr1, const void *ptr2) {
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "laser.h"
|
||||
#include "dialog.h"
|
||||
#include "list.h"
|
||||
#include "refs.h"
|
||||
#include "config.h"
|
||||
#include "resource/resource.h"
|
||||
#include "replay/state.h"
|
||||
|
@ -109,8 +108,6 @@ typedef struct {
|
|||
Boss *boss;
|
||||
Dialog *dialog;
|
||||
|
||||
RefArray refs;
|
||||
|
||||
GameoverType gameover;
|
||||
int gameover_time;
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ static void taisei_shutdown(void) {
|
|||
progress_unload();
|
||||
|
||||
gamemode_shutdown();
|
||||
free_all_refs();
|
||||
shutdown_resources();
|
||||
taskmgr_global_shutdown();
|
||||
audio_shutdown();
|
||||
|
|
|
@ -86,7 +86,6 @@ taisei_src = files(
|
|||
'projectile.c',
|
||||
'projectile_prototypes.c',
|
||||
'random.c',
|
||||
'refs.c',
|
||||
'stage.c',
|
||||
'stagedraw.c',
|
||||
'stageinfo.c',
|
||||
|
|
100
src/refs.c
100
src/refs.c
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
||||
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
||||
*/
|
||||
|
||||
#include "taisei.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "refs.h"
|
||||
|
||||
/*
|
||||
* NOTE: if you're here to attempt fixing any of this braindeath, better just delete the file and start over
|
||||
*/
|
||||
|
||||
PRAGMA(message "Delete this file when no users left")
|
||||
DIAGNOSTIC(ignored "-Wdeprecated-declarations")
|
||||
|
||||
void *_FREEREF;
|
||||
|
||||
#ifdef DEBUG
|
||||
// #define DEBUG_REFS
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_REFS
|
||||
#define REFLOG(...) log_debug(__VA_ARGS__);
|
||||
#else
|
||||
#define REFLOG(...)
|
||||
#endif
|
||||
|
||||
int add_ref(void *ptr) {
|
||||
int i, firstfree = -1;
|
||||
|
||||
for(i = 0; i < global.refs.count; i++) {
|
||||
if(global.refs.ptrs[i].ptr == ptr) {
|
||||
global.refs.ptrs[i].refs++;
|
||||
REFLOG("increased refcount for %p (ref %i): %i", ptr, i, global.refs.ptrs[i].refs);
|
||||
return i;
|
||||
} else if(firstfree < 0 && global.refs.ptrs[i].ptr == FREEREF) {
|
||||
firstfree = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(firstfree >= 0) {
|
||||
global.refs.ptrs[firstfree].ptr = ptr;
|
||||
global.refs.ptrs[firstfree].refs = 1;
|
||||
REFLOG("found free ref for %p: %i", ptr, firstfree);
|
||||
return firstfree;
|
||||
}
|
||||
|
||||
global.refs.ptrs = realloc(global.refs.ptrs, (++global.refs.count)*sizeof(Reference));
|
||||
global.refs.ptrs[global.refs.count - 1].ptr = ptr;
|
||||
global.refs.ptrs[global.refs.count - 1].refs = 1;
|
||||
REFLOG("new ref for %p: %i", ptr, global.refs.count - 1);
|
||||
|
||||
return global.refs.count - 1;
|
||||
}
|
||||
|
||||
void del_ref(void *ptr) {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < global.refs.count; i++)
|
||||
if(global.refs.ptrs[i].ptr == ptr)
|
||||
global.refs.ptrs[i].ptr = NULL;
|
||||
}
|
||||
|
||||
void free_ref(int i) {
|
||||
if(i < 0)
|
||||
return;
|
||||
|
||||
global.refs.ptrs[i].refs--;
|
||||
REFLOG("decreased refcount for %p (ref %i): %i", global.refs.ptrs[i].ptr, i, global.refs.ptrs[i].refs);
|
||||
|
||||
if(global.refs.ptrs[i].refs <= 0) {
|
||||
global.refs.ptrs[i].ptr = FREEREF;
|
||||
global.refs.ptrs[i].refs = 0;
|
||||
REFLOG("ref %i is now free", i);
|
||||
}
|
||||
}
|
||||
|
||||
void free_all_refs(void) {
|
||||
int inuse = 0;
|
||||
int inuse_unique = 0;
|
||||
|
||||
for(int i = 0; i < global.refs.count; i++) {
|
||||
if(global.refs.ptrs[i].refs) {
|
||||
inuse += global.refs.ptrs[i].refs;
|
||||
inuse_unique += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(inuse) {
|
||||
log_warn("%i refs were still in use (%i unique, %i total allocated)", inuse, inuse_unique, global.refs.count);
|
||||
}
|
||||
|
||||
free(global.refs.ptrs);
|
||||
memset(&global.refs, 0, sizeof(RefArray));
|
||||
}
|
37
src/refs.h
37
src/refs.h
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
||||
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "taisei.h"
|
||||
|
||||
/*
|
||||
* NOTE: if you're here to attempt fixing any of this braindeath, better just delete the file and start over
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
void *ptr;
|
||||
int refs;
|
||||
} Reference;
|
||||
|
||||
#define DEPRECATED_REFS \
|
||||
attr_deprecated("Use tasks and boxed entities instead")
|
||||
|
||||
typedef struct {
|
||||
Reference *ptrs DEPRECATED_REFS;
|
||||
int count;
|
||||
} RefArray;
|
||||
|
||||
extern void *_FREEREF;
|
||||
#define FREEREF &_FREEREF
|
||||
#define REF(p) (global.refs.ptrs[(int)(p)].ptr)
|
||||
int add_ref(void *ptr) DEPRECATED_REFS;
|
||||
void del_ref(void *ptr);
|
||||
void free_ref(int i);
|
||||
void free_all_refs(void);
|
||||
|
||||
#define UPDATE_REF(ref, ptr) ((ptr) = REF(ref))
|
|
@ -1170,7 +1170,6 @@ void stage_end_loop(void *ctx) {
|
|||
cosched_finish(&s->sched);
|
||||
stage_free();
|
||||
player_free(&global.plr);
|
||||
free_all_refs();
|
||||
ent_shutdown();
|
||||
rng_make_active(&global.rand_visual);
|
||||
stage_objpools_free();
|
||||
|
|
Loading…
Reference in a new issue