Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
97d7c330
Commit
97d7c330
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
add guid support
parent
8361c880
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
fggl/CMakeLists.txt
+4
-2
4 additions, 2 deletions
fggl/CMakeLists.txt
fggl/util/CMakeLists.txt
+4
-0
4 additions, 0 deletions
fggl/util/CMakeLists.txt
fggl/util/guid.cpp
+46
-0
46 additions, 0 deletions
fggl/util/guid.cpp
include/fggl/util/guid.hpp
+66
-0
66 additions, 0 deletions
include/fggl/util/guid.hpp
with
120 additions
and
2 deletions
fggl/CMakeLists.txt
+
4
−
2
View file @
97d7c330
...
...
@@ -31,6 +31,10 @@ if (CLANG_TIDY_FOUND)
set
(
CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*,-llvmlibc-*,-fuchsia-*,-cppcoreguidelines-*,-android-*,-llvm-*,-altera-*,-modernize-use-trailing-return-type
)
endif
()
# the important stuff everything else uses
add_subdirectory
(
math
)
add_subdirectory
(
util
)
target_sources
(
${
PROJECT_NAME
}
PRIVATE
app.cpp
...
...
@@ -58,8 +62,6 @@ target_sources(${PROJECT_NAME}
gui/fonts.cpp
)
add_subdirectory
(
math
)
# yaml-cpp for configs and storage
find_package
(
yaml-cpp
)
target_link_libraries
(
fggl PUBLIC yaml-cpp
)
...
...
This diff is collapsed.
Click to expand it.
fggl/util/CMakeLists.txt
0 → 100644
+
4
−
0
View file @
97d7c330
target_sources
(
fggl
PRIVATE
guid.cpp
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fggl/util/guid.cpp
0 → 100644
+
46
−
0
View file @
97d7c330
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 23/07/22.
//
#include
<map>
#include
<string>
#include
<cassert>
#include
"fggl/util/guid.hpp"
namespace
fggl
::
util
{
static
std
::
map
<
GUID
,
std
::
string
>
guidTable
;
GUID
internString
(
const
char
*
str
)
{
GUID
guid
=
make_guid
(
str
);
auto
tableValue
=
guidTable
.
find
(
guid
);
if
(
tableValue
!=
guidTable
.
end
())
{
assert
(
tableValue
->
second
==
str
);
}
else
{
guidTable
[
guid
]
=
str
;
}
}
std
::
string
guidToString
(
GUID
guid
)
{
auto
tableValue
=
guidTable
.
find
(
guid
);
if
(
tableValue
!=
guidTable
.
end
())
{
return
tableValue
->
second
;
}
else
{
return
"FGGL_UNKNOWN_GUID"
;
}
}
}
This diff is collapsed.
Click to expand it.
include/fggl/util/guid.hpp
0 → 100644
+
66
−
0
View file @
97d7c330
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 23/07/22.
//
#ifndef FGGL_UTIL_GUID_HPP
#define FGGL_UTIL_GUID_HPP
#include
<cstdint>
#include
"fggl/util/safety.hpp"
namespace
fggl
::
util
{
using
GUID
=
OpaqueName
<
std
::
uint64_t
,
struct
GuidTag
>
;
constexpr
uint32_t
FNV_PRIME_32
=
0x01000193
;
constexpr
uint32_t
FNV_OFFSET_BASIS_32
=
0x811c9dc5
;
constexpr
uint64_t
FNV_PRIME_64
=
0x00000100000001B3
;
constexpr
uint64_t
FNV_OFFSET_BASIS_64
=
0xcbf29ce484222325
;
constexpr
uint32_t
hash_fnv0a_32
(
const
char
*
str
)
{
uint32_t
hash
=
FNV_OFFSET_BASIS_32
;
for
(
int
i
=
0
;
str
[
i
]
!=
'\0'
;
i
++
)
{
hash
=
hash
^
str
[
i
];
hash
=
hash
*
FNV_PRIME_32
;
}
return
hash
;
}
constexpr
uint64_t
hash_fnv0a_64
(
const
char
*
str
)
{
uint64_t
hash
=
FNV_OFFSET_BASIS_64
;
for
(
int
i
=
0
;
str
[
i
]
!=
'\0'
;
i
++
)
{
hash
=
hash
^
str
[
i
];
hash
=
hash
*
FNV_PRIME_64
;
}
return
hash
;
}
constexpr
GUID
make_guid
(
const
char
*
str
)
{
return
GUID
::
make
(
hash_fnv0a_64
(
str
));
}
constexpr
GUID
operator
""
_fid
(
const
char
*
str
)
{
return
make_guid
(
str
);
}
// debug-only functions
GUID
internString
(
const
char
*
str
);
std
::
string
guidToString
(
GUID
guid
);
}
// namespace fggl::util
#endif //FGGL_UTIL_GUID_HPP
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment