Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d34c02d
added VSCode specific folders to .gitignore for my mental sanity
Duskhorn Sep 5, 2022
9722139
added VSCode specific folders to .gitignore for my mental sanity part 2
Duskhorn Sep 5, 2022
e3f8a1e
std::map (issue #257) and ENUMERATE removal part 1
Duskhorn Sep 5, 2022
d6b38a7
ENUMERATE removal part 2
Duskhorn Sep 5, 2022
cbcca7c
rebased => idents std::map in command.cpp (issue #257)
Duskhorn Sep 5, 2022
eb9ffc8
rebase part 2
Duskhorn Sep 5, 2022
f64ca0d
changed window, may have broken something. I'm not familiar of what h…
Duskhorn Sep 5, 2022
3cf04e0
more work towards Issue #257
Duskhorn Sep 5, 2022
9a2c059
ui.cpp for #257
Duskhorn Sep 5, 2022
e861ba9
animmodel.h and .cpp for #257
Duskhorn Sep 5, 2022
2b2c916
I may have broken this, because I don't understand hashset. Wish me l…
Duskhorn Sep 5, 2022
f171d64
rendermodel for issue #257
Duskhorn Sep 5, 2022
21deeee
rendertext for #257
Duskhorn Sep 5, 2022
dc39026
shader for #257
Duskhorn Sep 5, 2022
82b966b
last commit, brain mushy
Duskhorn Sep 5, 2022
a136eaa
.gitignore
Duskhorn Sep 7, 2022
3208416
typo
Duskhorn Sep 7, 2022
7b6b3ba
man I'm so bad at this
Duskhorn Sep 7, 2022
b371b89
fixed the cs.h
Duskhorn Sep 7, 2022
3672056
fixed last things..?
Duskhorn Sep 7, 2022
f288e1a
this errors so badly, and I don't know what to do
Duskhorn Sep 7, 2022
101ed8f
overloaded std::hash<animmodel::shaderparam>
Duskhorn Sep 8, 2022
1a79799
Merge branch 'project-imprimis:main' into map
Duskhorn Sep 8, 2022
0ecf3e6
typo in docstring
Duskhorn Sep 8, 2022
40fd71a
added operator== overload for animmodel::shaderparams
Duskhorn Sep 8, 2022
3ded74c
moved operator overload definition in .cpp file
Duskhorn Sep 8, 2022
cd85b33
blank slate, reverted changes
Duskhorn Sep 8, 2022
1ee9423
Merge branch 'project-imprimis:main' into map
Duskhorn Sep 14, 2022
c1664ff
merged main into current branch
Duskhorn Feb 13, 2023
614929f
fixed for loop indentations to fit formatting style
Duskhorn Feb 13, 2023
dcab423
fixed code formatting
Duskhorn Feb 13, 2023
47d2638
partial commit
Duskhorn Mar 1, 2023
8bf85f8
Merge branch 'project-imprimis:main' into map
Duskhorn Mar 1, 2023
90277e3
console.cpp cleanup
Duskhorn Mar 1, 2023
b870a15
added st::hash and operator== for FileVal
Duskhorn Mar 1, 2023
033064e
cleaned up octarender.cpp
Duskhorn Mar 1, 2023
c5a31b9
octarenderer hash structs and stuff
Duskhorn Mar 1, 2023
8b63228
renderlights and renderva cleanup
Duskhorn Mar 1, 2023
86eee0b
fixed the compilation error
Duskhorn Mar 1, 2023
44f438f
batch of fixes for console.cpp
Duskhorn Mar 2, 2023
35f5ad3
batch of fixes or animmodel.cpp/.h
Duskhorn Mar 2, 2023
22e2a26
trailing whitespaces
Duskhorn Mar 2, 2023
4d8e1b1
first batch of fixes for octarender.cpp
Duskhorn Mar 2, 2023
705d982
second batch of fixes for console.cpp
Duskhorn Mar 2, 2023
92aca22
removed unnecessary auto in renderlights.cpp
Duskhorn Mar 2, 2023
5d42085
corrected insert_or_assign() with a find() and optional insert
Duskhorn Mar 2, 2023
fa55b02
fixed issues in shader.cpp
Duskhorn Mar 2, 2023
0febcd7
fixed a bug - callng size() instead of clear() on a vector to clear it
Duskhorn Mar 3, 2023
409bd35
one statement per line, please
Duskhorn Mar 3, 2023
2ed5400
Merge branch 'project-imprimis:main' into map2
Duskhorn Mar 3, 2023
56fb292
fixes for rendertext.cpp
Duskhorn Mar 3, 2023
20ecbc7
removed superfluous commented out code
Duskhorn Mar 3, 2023
db5c316
removed superfluous comments part 2
Duskhorn Mar 3, 2023
a2f70e1
removed hashtables in skelmodel.h/.cpp
Duskhorn Mar 3, 2023
78092e7
removed unused s
Duskhorn Mar 3, 2023
e158a18
Merge branch 'project-imprimis:main' into map2
Duskhorn Mar 4, 2023
b787644
Merge branch 'project-imprimis:main' into map2
Duskhorn Mar 6, 2023
104f5d2
hashtavle<vec, int> removed and changed
Duskhorn Mar 6, 2023
e54284a
removed hashtable<ivec, int>; index didn't really need to be a pointe…
Duskhorn Mar 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ src/tess_server
*.srctrldb
*.srctrlbm
*.srctrlprj
.ionide
# Ignore VSCode specific files
.ionide/
.vscode/*
# Files auto-produced by CMake
cmake-build-*/
# Documentation files in the docs folder.
Expand All @@ -26,4 +28,4 @@ docs
# Ignore Code Spell Checker plugin files.
cspell.json
# Ignore html folder produced by Doxygen/Doxywizard.
html/
html/
103 changes: 65 additions & 38 deletions src/engine/interface/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "../libprimis-headers/cube.h"
#include "../../shared/stream.h"
#include "../../shared/hashtable.h"

#include "console.h"
#include "control.h"
Expand All @@ -25,17 +24,21 @@ struct FilesKey

FilesKey() {}
FilesKey(int type, const char *dir, const char *ext) : type(type), dir(dir), ext(ext) {}

};

static inline bool htcmp(const FilesKey &x, const FilesKey &y)
{
static inline bool operator==(const FilesKey &x, const FilesKey &y) {
return x.type == y.type && !std::strcmp(x.dir, y.dir) && (x.ext == y.ext || (x.ext && y.ext && !std::strcmp(x.ext, y.ext)));
}

static inline uint hthash(const FilesKey &k)
{
return hthash(k.dir);
}
template<>
struct std::hash<FilesKey> {
size_t operator()(const FilesKey &k) const noexcept {
return std::hash<const char*>{}(k.dir);
}
};



namespace
{
Expand Down Expand Up @@ -294,7 +297,7 @@ namespace
}
}

hashtable<int, KeyM> keyms(256);
static std::map<int, KeyM> keyms;

void keymap(int *code, char *key)
{
Expand All @@ -312,7 +315,7 @@ namespace
void searchbinds(char *action, int type)
{
std::vector<char> names;
ENUMERATE(keyms, KeyM, km,
for(auto &[k, km] : keyms)
{
if(!std::strcmp(km.actions[type], action))
{
Expand All @@ -325,20 +328,20 @@ namespace
names.push_back(km.name[i]);
}
}
});
};
names.push_back('\0');
result(names.data());
}

KeyM *findbind(char *key)
{
ENUMERATE(keyms, KeyM, km,
for(auto &[k, km] : keyms)
{
if(!strcasecmp(km.name, key))
{
return &km;
}
});
};
return nullptr;
}

Expand Down Expand Up @@ -896,8 +899,9 @@ namespace
return d;
}

hashtable<FilesKey, FilesVal *> completefiles;
hashtable<char *, FilesVal *> completions;
std::unordered_map<FilesKey, FilesVal *> completefiles;
std::unordered_map<std::string, FilesVal *> completions;


int completesize = 0;
char *lastcomplete = nullptr;
Expand All @@ -916,10 +920,10 @@ namespace
}
if(!dir[0])
{
FilesVal **hasfiles = completions.access(command);
if(hasfiles)
auto hasfilesiterator = completions.find(command);
if(hasfilesiterator != completions.end())
{
*hasfiles = nullptr;
hasfilesiterator->second = nullptr;
}
return;
}
Expand All @@ -943,25 +947,28 @@ namespace
}
}
FilesKey key(type, dir, ext);
FilesVal **val = completefiles.access(key);
if(!val)
auto valiterator = completefiles.find(key);
FilesVal *val = nullptr;
if(valiterator == completefiles.end())
{
val = valiterator->second;
FilesVal *f = new FilesVal(type, dir, ext);
if(type==Files_List)
{
explodelist(dir, f->files);
}
val = &completefiles[FilesKey(type, f->dir, f->ext)];
*val = f;
val = completefiles[FilesKey(type, f->dir, f->ext)];
val = f;
}
FilesVal **hasfiles = completions.access(command);
if(hasfiles)
auto hasfilesiterator = completions.find(command);
FilesVal *hasfiles = nullptr;
if(hasfilesiterator != completions.end())
{
*hasfiles = *val;
hasfiles = val;
}
else
{
completions[newstring(command)] = *val;
completions[command] = val;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is correct, because operator[] takes a const char *, but it's a little suspicious that this function previously leaked memory for no reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did I introduce a memory leak? :@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there was a leak before

}
}

Expand Down Expand Up @@ -1002,7 +1009,9 @@ namespace
char *end = std::strchr(&s[cmdlen], ' ');
if(end)
{
f = completions.find(stringslice(&s[cmdlen], end), nullptr);
const char *slice = stringslice(&s[cmdlen], end).str;
auto findf = completions.find(slice);
f = (findf == completions.end()) ? nullptr : findf->second;
}
}
const char *nextcomplete = nullptr;
Expand Down Expand Up @@ -1067,7 +1076,10 @@ void processtextinput(const char *str, int len)

void processkey(int code, bool isdown, int map)
{
KeyM *haskey = keyms.access(code);

auto haskeyiterator = keyms.find(code);
KeyM *haskey = haskeyiterator == keyms.end() ? nullptr : &haskeyiterator->second;

if(haskey && haskey->pressed)
{
execbind(*haskey, isdown, map); // allow pressed keys to release
Expand Down Expand Up @@ -1151,7 +1163,7 @@ void conoutf(int type, const char *fmt, ...)

const char *getkeyname(int code)
{
KeyM *km = keyms.access(code);
KeyM *km = &keyms[code];
return km ? km->name : nullptr;
}

Expand All @@ -1174,7 +1186,10 @@ void writebinds(std::fstream& f)
{
static const char * const cmds[3] = { "bind", "specbind", "editbind" };
std::vector<KeyM *> binds;
ENUMERATE(keyms, KeyM, km, binds.push_back(&km));
for(auto &[k, km] : keyms)
{
binds.push_back(&km);
}
std::sort(binds.begin(), binds.end());
for(int j = 0; j < 3; ++j)
{
Expand All @@ -1199,18 +1214,18 @@ void writebinds(std::fstream& f)
//print to a stream f the listcompletions in the completions filesval
void writecompletions(std::fstream& f)
{
std::vector<char *> cmds;
ENUMERATE_KT(completions, char *, k, FilesVal *, v,
std::vector<const char *> cmds;
for (auto& [k,v]: completions)
{
if(v)
{
cmds.push_back(k);
cmds.push_back(k.c_str());
}
});
}
std::sort(cmds.begin(), cmds.end());
for(uint i = 0; i < cmds.size(); i++)
{
char *k = cmds[i];
const char *k = cmds[i];
Comment thread
Duskhorn marked this conversation as resolved.
FilesVal *v = completions[k];
if(v->type==Files_List)
{
Expand Down Expand Up @@ -1307,25 +1322,37 @@ void initconsolecmds()

static auto clearbinds = [] ()
{
ENUMERATE(keyms, KeyM, km, km.clear(KeyM::Action_Default));
for(auto &[k, km] : keyms)
{
km.clear(KeyM::Action_Default);
}
};
addcommand("clearbinds", reinterpret_cast<identfun>(+clearbinds), "", Id_Command);

static auto clearspecbinds = [] ()
{
ENUMERATE(keyms, KeyM, km, km.clear(KeyM::Action_Spectator));
for(auto &[k, km] : keyms)
{
km.clear(KeyM::Action_Spectator);
}
};
addcommand("clearspecbinds", reinterpret_cast<identfun>(+clearspecbinds), "", Id_Command);

static auto cleareditbinds = [] ()
{
ENUMERATE(keyms, KeyM, km, km.clear(KeyM::Action_Editing));
for(auto &[k, km] : keyms)
{
km.clear(KeyM::Action_Editing);
}
};
addcommand("cleareditbinds", reinterpret_cast<identfun>(+cleareditbinds), "", Id_Command);

static auto clearallbinds = [] ()
{
ENUMERATE(keyms, KeyM, km, km.clear());
for(auto &[k, km] : keyms)
{
km.clear();
}
};
addcommand("clearallbinds", reinterpret_cast<identfun>(+clearallbinds), "", Id_Command);
addcommand("inputcommand", reinterpret_cast<identfun>(inputcommand), "ssss", Id_Command);
Expand Down
25 changes: 13 additions & 12 deletions src/engine/interface/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "../../shared/geomexts.h"
#include "../../shared/glemu.h"
#include "../../shared/glexts.h"
#include "../../shared/hashtable.h"

#include "console.h"
#include "control.h"
Expand Down Expand Up @@ -979,7 +978,7 @@ namespace UI
}
};

static hashnameset<Window *> windows;
static std::map<std::string, Window *> windows;

void ClipArea::scissor()
{
Expand Down Expand Up @@ -4379,14 +4378,16 @@ namespace UI
//new ui command
void newui(char *name, char *contents, char *onshow, char *onhide)
{
Window *window = windows.find(name, nullptr);
if(window)
auto search = windows.find(name);
if(search != windows.end())
{
auto [key, window] = *search; // I may have broken this, remove this comment if engine compiles/works. Issue #257
if (window == UI::window)
{
return;
}
world->hide(window); windows.remove(name);
world->hide(window);
windows.erase(name);
delete window;
}
windows[name] = new Window(name, contents, onshow, onhide);
Expand Down Expand Up @@ -4420,8 +4421,8 @@ namespace UI

bool showui(const char *name)
{
Window *window = windows.find(name, nullptr);
return window && world->show(window);
auto search = windows.find(name);
return search != windows.end() && world->show(search->second);
}

bool hideui(const char *name)
Expand All @@ -4430,8 +4431,8 @@ namespace UI
{
return world->hideall() > 0;
}
Window *window = windows.find(name, nullptr);
return window && world->hide(window);
auto search = windows.find(name);
return search != windows.end() && world->hide(search->second);
}

bool toggleui(const char *name)
Expand Down Expand Up @@ -4462,8 +4463,8 @@ namespace UI
{
return world->children.size() > 0;
}
Window *window = windows.find(name, nullptr);
return window && std::find(world->children.begin(), world->children.end(), window) != world->children.end();
auto search = windows.find(name);
return search != windows.end() && std::find(world->children.begin(), world->children.end(), search->second) != world->children.end();
}

void ifstateval(bool state, tagval * t, tagval * f)
Expand Down Expand Up @@ -4838,7 +4839,7 @@ namespace UI
void cleanup()
{
world->children.resize(0);
ENUMERATE(windows, Window *, w, delete w);
for(auto &[k, w] : windows) { delete w; }
windows.clear();
if(world)
{
Expand Down
15 changes: 7 additions & 8 deletions src/engine/model/animmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ Texture *animmodel::lasttex = nullptr,
int animmodel::matrixpos = 0;
matrix4 animmodel::matrixstack[64];

hashtable<animmodel::shaderparams, animmodel::ShaderParamsKey> animmodel::ShaderParamsKey::keys;
std::unordered_map<animmodel::shaderparams, animmodel::ShaderParamsKey> animmodel::ShaderParamsKey::keys;
int animmodel::ShaderParamsKey::firstversion = 0,
animmodel::ShaderParamsKey::lastversion = 1;

uint hthash(const animmodel::shaderparams &k)
{
return memhash(&k, sizeof(k));
}

bool htcmp(const animmodel::shaderparams &x, const animmodel::shaderparams &y)
bool animmodel::shaderparams::operator==(const animmodel::shaderparams& other) const
{
return !std::memcmp(&x, &y, sizeof(animmodel::shaderparams));
return !std::memcmp(this, &other, sizeof(animmodel::shaderparams));
}

//animmodel
Expand Down Expand Up @@ -170,7 +166,10 @@ bool animmodel::ShaderParamsKey::checkversion()
version = lastversion;
if(++lastversion <= 0)
{
ENUMERATE(keys, ShaderParamsKey, key, key.version = -1);
for(auto& [k, key] : keys)
{
key.version = -1;
}
firstversion = 0;
lastversion = 1;
version = 0;
Expand Down
Loading