Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
cpp-project
Commits
fe650c77
Commit
fe650c77
authored
6 months ago
by
TheUltimateOptimist
Browse files
Options
Downloads
Patches
Plain Diff
started implementing loadLevel
parent
bb0f09e9
Branches
Branches containing commit
No related tags found
1 merge request
!17
Merge feature to load levels from file
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/level.cpp
+33
-0
33 additions, 0 deletions
src/level.cpp
src/level.hpp
+2
-0
2 additions, 0 deletions
src/level.hpp
src/main.cpp
+2
-0
2 additions, 0 deletions
src/main.cpp
with
37 additions
and
0 deletions
src/level.cpp
+
33
−
0
View file @
fe650c77
...
...
@@ -3,6 +3,9 @@
#include
"building.hpp"
#include
"effect.hpp"
#include
"engine.hpp"
#include
"highfive/H5File.hpp"
#include
<boost/property_tree/ptree.hpp>
#include
<boost/property_tree/xml_parser.hpp>
#include
"spritesheet.hpp"
#include
"unit.hpp"
#include
<SDL.h>
...
...
@@ -22,6 +25,36 @@ Level::Level(std::string name, int width, int height, std::vector<Tile> tiles,
}
};
Level
Level
::
loadLevel
(
std
::
string
path
)
{
HighFive
::
File
file
(
path
,
HighFive
::
File
::
ReadOnly
);
// read level metadata
std
::
string
level_metadata
;
file
.
getDataSet
(
"level/metadata"
).
read
(
level_metadata
);
// read tilesarray
std
::
vector
<
uint8_t
>
level_tilesarray
;
file
.
getDataSet
(
"level/tilesarray"
).
read
(
level_tilesarray
);
// extract metadata from xml
std
::
istringstream
xmlStream
(
level_metadata
);
boost
::
property_tree
::
ptree
pt
;
boost
::
property_tree
::
read_xml
(
xmlStream
,
pt
);
int
width
=
pt
.
get
<
int
>
(
"level.width"
);
int
height
=
pt
.
get
<
int
>
(
"level.height"
);
std
::
string
name
=
pt
.
get
<
std
::
string
>
(
"level.name"
);
std
::
vector
<
Tile
>
tiles
;
tiles
.
reserve
(
width
*
height
);
for
(
uint8_t
value
:
level_tilesarray
)
{
tiles
.
push_back
(
Tile
())
}
throw
std
::
runtime_error
(
"some"
);
};
void
Level
::
render
(
Engine
&
engine
,
std
::
vector
<
SDL_Event
>
&
events
)
{
const
int
RENDERING_SCALE
=
3
;
...
...
This diff is collapsed.
Click to expand it.
src/level.hpp
+
2
−
0
View file @
fe650c77
...
...
@@ -21,6 +21,8 @@ public:
std
::
vector
<
Building
>
buildings
,
std
::
vector
<
Unit
>
units
,
std
::
vector
<
Effect
>
);
static
Level
loadLevel
(
std
::
string
path
);
void
render
(
Engine
&
engine
,
std
::
vector
<
SDL_Event
>
&
events
);
private:
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
2
−
0
View file @
fe650c77
...
...
@@ -30,6 +30,8 @@ int main() {
Window
window
(
"Advanced Wars"
,
960
,
960
);
Engine
engine
(
window
);
Level
levell
=
Level
::
loadLevel
(
"level.h5"
);
return
0
;
// Construct a level
std
::
vector
<
Tile
>
tiles
;
...
...
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