Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
okay hello everyone and welcome to
handmade hero we are on day 39 here this
is of course a full game and engine
coded live on Twitch in C and C++ using
no library's no engines we are basically
doing absolutely everything from scratch
largely sort of as a as both an
educational process and and just for fun
I think it's really good for you know on
both on both ends really for the type
type of person who actually enjoys
programming then being able to program
everything yourself is kind of a fun
thing to do especially nowadays when you
don't get to do that all that often and
I've certainly been having fun doing it
I think a lot of the people out there
have been too and also it's a great
thing for educational purposes because a
lot of people just don't have a chance a
lot of times depending on sort of what
their program range was to go through
and do all kinds of interesting
low-level stuff and build an entire game
engine from the ground up and that sort
of thing and so they're just a lot of
cool stuff you could learn in there I
think anyway I always feel like most all
the most interesting stuff that I've
ever learned in programming came from
having to tackle you know hard low-level
problems really honestly even the good
high-level programming stuff that I know
is largely from having to do sort of you
know having to think about hard
constraints and that sort of stuff so
anyway right now we are at the point
where we sort of gotten we're sort of
wrapping up the stuff that we can
reasonably do before we learn some math
basically is what what I guess how I
would say it we've wrapped up sort of
the basic stuff of putting sprites on
the screen you know loading bitmaps
doing some basic alpha blending
techniques building a tile map and
moving around through the tile map that
sort of stuff
but in order to start moving forward
since in you know on the on the engine
further what we kind of need to do is
we're probably going to need to start
doing some math very soon so I think
today what we're probably going to do is
we're going to go through and we're just
going to kind of like do a pass over the
stuff that we've got so far and just
kind of like cleaning things up and sort
of get things into place where we're a
little be happy with them so that we can
start clearing the way for doing really
maybe starting to have a serious
discussion about gain math and what sort
of math we need to know and what all the
different types of
that tend to come up in games and so
then start to go through some of the one
the most basic ones that we will need in
order to move forwards which are basic
2d vector math and stuff like that which
we're gonna need for just about
everything that we're going to do so if
you went and made here at organ preorder
the game using the little P order button
you should have gotten an email with a
link that allows you to download the
source code and the test assets that we
use as well there's two zips up there
make sure you grab both of those and
inside the source code zip there's a
bunch of different zips resource codes
from every different day we're on day 39
right now so if you want to follow along
at home unzip day 38 source code day 38
source codes what we are starting with
now and if you unzip that you will be at
the exact location that I am starting
with today so you could follow along
exactly the way that we're with with
exactly what we're doing so if you guys
remember we've gotten to the point at
the end of last stream where we were
able to blip basically things on top of
other things which allows us essentially
to compose whatever we want in terms of
graphics now we can you know layer
sprites on top of each other all day
long but we had only just finished that
so we didn't just we didn't really do
anything with it
so I was thinking maybe today what we
could do is just load in our our little
hero sprite and he's in three pieces as
I think I showed when I was going
through the different sprites that were
in there he's in three different pieces
so maybe we'll go in and load his three
different pieces and we also have four
facing directions for him so maybe we'll
load in all of those and we'll sort of
make a thing where he can as we move he
faces the direction you know that we're
moving or something like that just
something basic to sort of clean up the
bitmap loading and the bitmap display
code into something that we're
relatively comfortable with for the
moment before we kind of move on to
trying to do a little bit more serious
stuff again and where we'd have to start
talking about math for reals for reals
with a Z so okay assuming that we're in
that situation
right now we are loading all of our
bitmaps we haven't talked really very
much about asset management in terms of
how we're managing loading stuff in the
code and that's actually deliberate it's
not something that I think is really
worth discussing at the moment I think
that's going to be something that comes
into play once we have a bit of the
renderer sort of the real renderer once
we kind of have more of a real renderer
written is really the more the
appropriate time start thinking about
that so right now we just have the sort
of the most basic thing you
doing a game which is loading all the
assets at startup not a particularly
useful thing to do
if you're active talking about a
shipping game because like I said in
this game we're going to be streaming
our assets in so loading everything at
startup isn't really an option for us
but well we're just developing things
that's certainly fine so I'm gonna have
to load these different hero things for
four different directions so I'm just
gonna go ahead and make life a little
easier on myself for now and just say
that we have sort of a hero bitmaps
structure and that we'll have basically
the different pieces the head the cape
and the torso each for you know the
different facing directions of the hero
so that I can basis there we have hero
bitmaps and the hero bitmaps that we
have are for the four facing direction
so we'll just say hero bitmaps and I
guess I'll do I don't know we could do
something like just a brackets for I
guess because we will essentially have
to map into that somehow we'll think
about that in a second but anyway if I
want to load those in I've already got
code that loads each of the each of the
test pieces in here into the hero hey I
don't know what what happened to our
hero torso code I must have actually hit
ctrl K that's a mistake so basically we
already have code that does that which
is this code right here but I need to
load one of those for each of the facing
directions like test your front you know
the sort of the front back side and all
that sort of stuff so I'm gonna go ahead
and do the stupidest possible thing here
just do hero bitmaps and I'm going to
substitute in basically one of these
like that for each of these ones that we
load like so and then I'm just going to
go ahead and call that four times
nothing particularly exciting here and
like I said well think I'll well think
harder about how we want to do this
stuff once we actually think about asset
loading and how we want to identify a
bit mass because in general you know you
don't want to have to have huge tables
of strings in your code at least I don't
and so that's not something that I would
encourage you to do when you're actually
doing the real code but for now it's
exactly the right thing to do because
you do not want to be thinking about
that while you're trying to work on
other pieces of the code
so here is the the set of files that we
have we have front back left and right
I'm not sure what the best way to map
those to 0 1 2 & 3 are at the moment so
I guess maybe what I will say is let's
go ahead and just do we'll just do maybe
start with with moving right in in that
0 slot and then you know I'll go I'll
basically do it almost like it was a
circle so then there's the there's up
it's after that like so and then this
would be left right and I guess it's not
it's not up it's actually that's that's
looking at his back right like so and
then and then front is down here you've
already got and so that'll load all
those bitmaps into memory for us and
it'll just go ahead and be using those
for the entire run of the game at the
moment if I go ahead and compile then we
will not be able to find that when we do
the hero head but we should be able to
do here a bitmap 0 dot had and now we
should basically be back to exactly
where we were before only now he's you
know the other facing direction right
but I'm gonna need actually to draw well
you know what I don't know why I keep
forgetting the fact that I can always
leave the code running we don't actually
have to don't have to I guess it said
just from a lot of stuff that I worked
on day to day doesn't have this feature
necessarily so you kind of get in the
habit
unfortunately oops that's not right so
if I have the head I have the torso and
I have the cape I guess the cape comes
over the torso basically want to do is I
want to draw these in reverse order
because remember this is a lot like
Photoshop things get layered on top of
each other so what I actually want is I
want the torso first if that's the thing
that's the lowest down in terms of what
gets shown then the Cape gets laid on
top of that then the head on top of that
and in theory that should reconstruct my
hero if if I'm not very much mistaken
and yes there he is
there's the little hero fellow and he is
facing in the in the direction to the
right which is what I expected
now I probably could also say here you
know if I had a facing direction for the
little fellow right
have facing direction equals zero let's
say and I went in here and said you know
facing Direction like this or something
then I would be able to also sort of
flip him around I suppose as I as I go
right if I flip it to one there he goes
- nice pacing that way three nice facing
towards us and so if I wanted him to
basically face the direction that he's
actually moving in 3000 okay don't think
3000 is very good things like been there
if I wanted to face for actually thing I
just need some way of specifying what it
was whatever that last direction was
that's the direction in which he moved
right so if I go in here and I just say
all right that facing direction you know
hero facing Direction is now a parameter
and then out here I can go ahead and
grab out the hero bitmaps thing that
that is appropriate based on that facing
Direction right I can go ahead and do
you know game state hero bitmaps for
game state hero facing direction that
would give me back that bitmap that I
actually want the whichever one you know
it's actually supposed to be and so then
if I go in here and just go ahead and
change these all to sort of operate off
of that then I've sort of made it so
that we can easily store in the game
strip state structure what it actually
is we want the hero facing direction to
be so if I go ahead and go over to the
code where we actually move the guy
around right with move up move down move
left and move right it'd be pretty
trivial for me to sort of go and just
set it to whichever key down you press
laughs which is a totally reasonable
thing to do for now since we don't
really again we haven't done that vector
mask so we can't really do much we
haven't really written any real hero
movement code yet and so it's it's you
know it's not really gonna be something
that we can do anything fancy with yet
but for now we can certainly set the
hero facing direction to whichever thing
you actually push down last so if the
hero you know was was was moving upward
we can set it to that moving up
direction if the hero was moving
downward we can side to that moving down
you know the left
and the right like so and then if I go
ahead and compile that or what's these
are supposed to be address of the bitmap
there now I should have a way to
basically have my my dude change
direction
oops and I've got I miss I miss typed at
once there so I've ever did my my two
directions what did I do
let's see here so if we're moving left
yes left is supposed to be to right is
supposed to be zero that's that's what I
said when I made it but I didn't
actually do it and so now the hero
actually does change for whatever
direction he moves in and I'd like to go
ahead and Center him on his rectangle as
well you'll notice that basically the
bitmap right now we we do have something
in fact this is probably something worth
talking about because we haven't really
addressed it and in the art assets yet
we're not actually at the level of
loading art assets where this sort of
stuff comes into play but we'll need to
do something as sort of a temporary a
temporary fix to it if you consider the
fact if you consider what these bitmaps
actually are right if we actually go and
you can see we're drawing the player's
bitmaps right all those three bitmaps
we're drawing them with this upper left
corner here this this is the point the
position that we're passing when we say
we want to draw those bitmaps there's a
bunch of information kind of there's a
bunch of sort of assumed information
that's all getting baked in there and
it's why for example the hero is kind of
nowhere near where our rectangle thinks
he should be this was our little test
rectangle that said where we thought the
hero should be and so it's not at all
correct right we'd expect the hero to
kind of be standing up you know with his
feet roughly where at the bottom of the
rectangle where was for example but
that's not at all what's happening and
so considering that situation right
what's going on there
well if you look at what we've got in
terms of assets if you go into the test
directory and look at what these assets
are let's say we open one of them up
well watch they'll open up all three for
a given facing Direction we'll open up
the front facing ones for now inside
GIMP and what you can actually see if
you take a look at these guys in fact
you know what I can do to that was
probably the wrong way to
a course that opens three different
copies of GIMP there for me thank you so
much GIMP
what I'll actually do is I'll go ahead
and we have the front torso loaded I'm
gonna load the head and the cape and so
now they're all in there as a layer
right they're all in as theirs as layers
and what you can see is basically the
the way the art comes in because these
are raw our assets that we're loading we
haven't process number than anything to
them basically they're just a giant
empty space around the guy which is
totally fine like we want that that's
what you want your artist to give you
but then you need to do work to kind of
process those down into final art assets
that you would use and you would store
all that up to space obviously and so on
so forth but the other important part of
this is that there's essentially an
implicit hot spot defined here
oftentimes what it's called it's
oftentimes called a hot spot on that's
like the old-school term for it it's
it's sort of what the used to call like
cursor locations and stuff that you'd
use for offsets it's I don't actually
know why the term is what it is
but there's an implicit sort of
alignment point you could think of which
is basically right down here where the
dude is standing is where we kind of
want to position him in the world right
we want to have this point aligned with
where we think the player's position is
like something like that right basically
right where he would be sort of standing
where he would be touching the ground
right and we don't actually have that
information yet and so what we're gonna
have to do in our eventual real art
files is we will have to have those
registration marks basically in there or
we'll have to set them manually one of
the other doesn't matter but you have to
do something along those lines and so if
I look in there I can actually see down
in the bottom here right here GIMP will
tell me what those pixel coordinates are
like 72 180 270 2 , 182 right you can
see as I move those are the X&Y
positions so we can go ahead and put
that in there we can say that it's 72
roughly 72 182 for that particular
facing direction right and that's that's
the one where he's facing the front so
in the one where he's facing the front
and in fact I guess we could sort of do
it here so that's it's 72
and 182 for the X and the y we could go
ahead and make this a little more
concise here and basically say well okay
there's these hero bitmaps and we're
going to introduce another thing which
is basically the align X and align Y
right for this bitmap set so that we
kind of know how to position them
relative to the points that we actually
care about in the world that makes sense
okay so what we want to do is we want to
basically have those registrations that
will just hard code for now into this
part of ourselves and then when we get
to the point where we actually are
talking about putting large numbers of
assets into the game what we'll need to
do is we'll need to have a way of
actually loading that data from
somewhere like that data will have to be
produced in a more efficient fashion we
probably don't want to sit here and hand
code it ourselves what we'd rather have
is some way of just marking it in
Photoshop or whatever it is and then
when those alright access get exported
we'll make sure they get exported to
something that we can read when we
process our art assets so I'm going to
go ahead here and just do something like
this where we can sort of have a nice
yeah something like that
in fact I guess what I could do yeah
this is actually pretty easy you could
actually do this and then I'll just do
bitmap Arrowhead equals debug load like
so and and bitmap arrow Cape so just
clean things up a little bit here so
there's not quite so verbose there we go
and now I'll also do bitmap align x
equals something and bitmap align y
equals something and then I'll move on
to the next fit map right so this will
just load our hero bitmaps as they work
so I'm just gonna go ahead and make that
change everywhere I think I can probably
I don't know you know it's always dicey
when I do this but we're gonna do it
anyway I think I think it's just it's
the right time to do it people and you
know when it's the right time to do it
you know and when it's the right time
you kind
just got to go with it you kind of got a
go with the flow sometimes so there we
go with that and then we'll put that
here so let's go ahead and get that
going on there we go to clean that up
and now we've got something a little
more respectable in terms of code we can
use okay so I'm gonna go ahead and just
manually for now do those offsets but
again that's just something you know
something definitely to pay attention to
you know if you didn't have me sitting
here telling you the sorts of things
that we'll probably do because I've done
on stuff like this before this would
basically a place where you'd want to
think in your head you know I don't want
to be sitting here manually open up
these bitmaps every time the artist
changes something looking to see where
that alignment point is like you can see
that that's going to be something that's
going to take time and you might art you
know you kind of want to think to
yourself what could what might we be
able to do that could sort of speed that
process up right like how could we how
could we make a better way of setting
these alignment points right and there's
a lot of different ways you could do it
but it's just something to be aware I'll
be kind of like it raises that little
red flag where you kind of got to think
to yourself what you know what's the
what's the end scheme here so it looks
like a like these are roughly the same I
don't know Yong Seon may have already
just kind of lined everything up for us
which is kind of nice so it looks like
they may all be roughly the same so we
won't have to really do yeah I think she
might have although that one's a little
different than than the other ones
probably but we could probably use them
all at the moment as as being 70 to 182
that's what that's what actually they
almost all look like is roughly that
value so we'll leave it like that but we
could tweak them later okay so now we've
got these loaded mm-hmm there we go
what why are you oh whoops that's no
good I didn't even realize I still had
the game loading my bad sorry guys okay
so now we've got our little fellow there
and what I want to do is like I said
I've got the information
there now where I could go ahead and
correct for where he should be relative
to that relative to the alignment point
and so what I need to do is I need to
have some way of actually taking that
alignment into account so in here where
I do this draw bitmap
I want to basically be able to change
the player left in the player top based
on that alignment amount and so what I'm
going to do is I'm going to introduce
probably a new function here which is a
draw a bitmap a line function or there
is a different thing I could do which is
I could make these basically be some
kind of registered coordinates it's a
little bit hard to say at the moment I
think possibly in the interest of oh
it's so tough to say sometimes you know
I'm not sure how we want to do this yet
so I think temporarily what I might do
is I might just pass these as optional
parameters into this thing we're gonna
want to do something fancier than this
later but I think we might just want to
have it in there right there for now and
we'll sort of when we have more of a
renderer there's gonna be more clearer
places where those should go in my
opinion so I think for now we'll just
leave it like that and we can go ahead
and say that the the hero bitmaps align
X and the hero bitmaps align Y can go
ahead and get passed in there alright so
we'll go ahead and compile that and what
I want to do now right is I want to
actually use those alignment points to
offset the place where we would be
drawing the guy and I think I actually
have to kinda remember what we actually
did for player we're passing player left
and player top but that's not what we
actually want anymore
we actually just want the players actual
location right so so we actually want to
know where the player actually is we
want a player ground point basically and
and we want that ground point in X&Y and
we what so so we don't really were not
so interested necessarily in these sort
of
adjustments for the players height and
the players width and so on right
that's not actually what we want to see
what we want to see here is we want to
see let's see something more like that
so that's gonna be the player ground
plane X and then player ground point Y
and then I'll go ahead and keep
computing the location for our rectangle
as well you might as well leave that
drawing but then in here so what I want
to do is I want to pass those points
that were aligning to right so I'm gonna
pass those instead of the the left on
top that's a player ground point Y there
we go
so now we're passing the right things in
and now that should make our guy up here
even more off-center because we're now
passing this point right here which
means it's drawing like this so now we
have to do is do that alignment to get
him back up to the right place so if I
go into that drop bitmap call you can
sort of see it's not gonna be
particularly difficult we've got our
real X and our real Y that coming in
here basically all we have to do is
subtract from those the values that we
have for our alignment right all we need
to do is say we want this align X and
this align Y to actually be sort of the
the alignment point versus the point
that we've been passed in so if you
think about what happens I'll go ahead
and draw it out for you here on our on
our handy-dandy whiteboard I don't know
why krita's still is passing a hand for
our cursor nobody really knows we don't
try to understand Crito we just accept
the fact that it does what it does and
so what I'm doing here right is we've
got a blitt routine and the blitt
routine is going to draw a rectangle
from like an upper corner it's gonna
copy these rows in here right but what
we have is we have a registration mark
right in the world but basically where
the player ground point is so this is
the ground point right and then we have
a bitmap that also has a registration
mark in it right that's measured from
that upper corner so what we want to do
if we are saying that these two
registration marks should line up then
we're relative to the ground point where
would we draw right that this bitmap
well the answer is we just invert right
whatever this was if we're saying that
the align X and the line Y is how you
from the upper corner to the alignment
point then getting back to the upper
corner is just gonna be a matter of
subtracting them right and so that's all
I'm going to actually do here because
I'm just going to go ahead and subtract
those aligned X and aligned Y points so
that I can offset my bitmap by the
amount that we possible that would be
necessary to move those alignment points
into into coinciding right and so now
you can see our little hero fellow he
actually is properly aligned with where
we thought he should be and that's all
good he's a little off in though in the
direction that I said maybe he would be
off in which is the side ones I wasn't
sure what we should set those alignments
to you but he's for the most part pretty
much fine and so that's a lot better
than what we had in there before now
what I'd like to do is I'd like to get
back to screen based stuff here you know
we had our tile map and then we started
doing scrolling just as a test thing I'd
like to get back to having things fixed
on the screen where we just walk in and
we walk around the screen instead of the
screen scrolling around us so I'd like
to go back and and and change things
back to going that way for a while until
just because I that's sort of the way
the game will mostly be played and we
don't kind of want this random stuff in
here for now because we're gonna start
working with the players actual movement
code alright so hopefully that was all
very straightforward nothing
particularly unusual going on there
let's see we got about 30 minutes left
which is quite some time okay
so what I want to do now is kind of
figure out some way to keep our camera
centered so that we can have our tile
maps back also I feel like we can
probably at this point stop drawing the
crazy backdrop for now well I mean we
could keep drawing that backdrop I guess
we could do a number of things I'd have
to think about exactly what we should be
doing it's a little bit difficult to say
because again trying to manage stuff at
this stage in the game we're kind of
thinking about all the different places
we could go there's so much there are so
many different places that we can go
obviously exploring because we have
every every part of the system is still
pretty much up in the air but basically
I guess what I'd say is do we want to
leave that
drawing the back up in there you know
maybe we do at the very least what I'd
like to do is just leave the sort of the
world fixed for now yeah so what I'd
like to do is I'd like to change it so
that instead of drawing out from around
the player because you remember this
right here drew our tile maps this was
our little debug thing for drawing what
was filled in the tile map I think what
I'm going to do is I'm going to change
it so that we have both a player P and a
camera P right so now I have a place
where the camera is looking and I have a
place where the players looking and
they're not going to be the same anymore
so now the camera P is basically going
to be you know the place around which we
Center that tile map rendering so all
the same stuff we were doing here we're
gonna do it's just we're not going to do
them from the player Pete right instead
of player P in here we're gonna do it
from this perspective of the camera and
so what we were doing remember if you
remember how we drew this tile map we
are essentially starting with whatever
tau the player was on we were saying
that was going to be centered in the
very middle of the screen and then we
were just gonna walk out words from
there to the ten picked tiles on either
side and I'm sorry ten pixels up and ten
tiles up and down so 20 tiles total and
40 tiles across so negative negative 22
20 which is more than actually was on
the screen we were kind of over drawing
a little bit we were we were going a
little bit further out so what I want to
do is just say okay we're gonna do
exactly the same thing only instead of
walking out from the player station when
I walk out from the cameras position so
everywhere that there was a player P in
here right I'm gonna change it to a
camera P right and so that's that's how
that's gonna work so now when we
initialize that player position at the
outset of the game we're going to
initialize the camera position to be
something logical as well so we
initialize the player position somewhere
in here there it is so we're gonna say
that there's also a stage where we
initialize the camera position and that
camera position should just be let's say
on that very first map that very first
tile map down in the corner
that Taichung I think we said basically
our tile system was going to be roughly
something like seventeen by nine or
something like that I think is what we
were saying so I'll do 17 divided by 2
and 9 divided by 2 for what that was
going to be game state camera P AB style
y equals 9 divided by 2 and you know
what it's interesting well I guess
that's fine so there we go
and we will go ahead and run that now
and see where we get
so essentially oh right and now we
actually have to do the work for doing
player position as well but now our
camera is going to be fixed and remember
we were cheating before we never
actually computed where to draw the
player we just drew him at the middle of
the screen so now we actually have to
compute where he is which means we're
going to have to do a relative
computation to see where is the player
relative to the camera because we know
the camera is at the screen center X and
screen center Y we know that's where the
camera is essentially going to be in
sort of the space when we draw the
screen because that's the definition of
the center of the screen is wherever the
camera is telling us to look so what we
need to do is we need to add something
to that right we need to say where is
the player relative to the camera so
that we know where to draw them relative
to the center of the screen right and so
what we need to do is we need to have
essentially a subtraction operator and
this kind of leads nicely into that mass
that I was talking about so this is
gonna be good because it will sort of it
sort of is a nice segue if you will for
talking about this tomorrow or Monday
whenever we decide to transition over it
to it but we've got these tile map
positions and basically what we want to
be able to do is we want to be able to
subtract right we want to be able to say
what is how do I get from one to another
if I have the player and I have the
camera how would I get from the camera
to the player because that's the
distance that I want to give in in sort
of that's that's what I want to add to
the screen Center to know where the
player is right so so what I'm gonna do
is I'm just gonna say okay let's
actually pretend we have that let's
actually just say that we had something
that could do is subtract
right and it could subtract a table map
position from another tile in that
position and will give us back the real
32 answer right so I'm just throwing in
a name for that at the moment I'm not
suggesting this is actually gonna be the
name eventually but that you know let's
do that subtraction right well that
subtraction is just going to be between
the gain the the player P right and the
camera P oops
like so now of course we might as well
just do we don't really want to have
multiple functions for this so we might
as well just do one that will actually
give us back the whole answer and again
this is kind of setting up the math so
we're gonna have to kind of do this in a
bit of a janky way for now because we
haven't introduced vectors yet so we're
just going to kind of see it and then
when we do our vectors which I guess
will be maybe tomorrow seems since it
seems like this is kind of the most
pressing concern we can kind of see how
it cleans our stuff up nicely so I could
basically say there's a tile map
difference function let's say and that's
gonna basically give us back the
difference in XY and Z when we do that
subtraction so if I do the subtraction I
could do it like this I could say that
we get back a tile map difference right
and that that difference is going to be
the difference between the player and
the camera once I have that difference
it's pretty easy for me to go ahead and
and add it in so I basically now would
have a way of getting to where I think
the player actually is so all I need to
do is make something that could subtract
these two and produce one of those as a
result so if I look at what has to
happen to do that right well part of it
is really really simple right if I've
got two of these let me go ahead and set
this up for a little more success here
if I had tile yeah like so so we've got
a tile map difference that we want to
return right and we want to basically
compute a DX dy and DZ out of that now
what I'd like to do is I'd like to take
in two tile map positions
in a canopy like so and then I would
like to say how do I subtract the two of
these well I know how to subtract the
offsets directly because the offsets
just are real 32 so producing another
floating-point offset by taking the
distance the difference of these two is
really really easy it would look like
this right that's all I would have to do
I would literally just subtract these
offsets but what I need to do now is I
need to account for these AB Stiles
right I don't have a way of accounting
for the AB Stiles
at all okay so in order to do that I
would I want to be able to do a signed
distance of some kind here so what I
might do is say all right we could do
the subtraction in float for now I have
to think about how I actually want to do
this eventually but for now we could
basically say all right we've got the
the signed distance which is the the d
tile distance right and that's going to
be you know the ABS tile X from a - the
ABS cloud Y like so on like so there we
go
so I'm gonna do that subtraction to get
these these deltas here detail X ETA Y
do TLC right and then those are in tiles
so in order to change the distance in
tiles I would need to know that tile
side in meters right I need to know that
tile map information so I'm gonna have
to take the tile map in order to do that
conversion right I need to know for
every one change when I do this how far
they in tiles I need to know how far
that's actually going to be in the real
meters units that we're using for
everything else so the tile side and
meters right that I'm gonna have to go
ahead and multiply in here in order to
in order to and I guess I could do that
down here as well there we go
so basically I have my detail X
and detail why tom at five meters deep
Tao why like so and outside in meters we
don't really know yet what our RZ should
really be in this case it's unclear that
we ever want to actually have a DZ in
this way but I'll put it to do in there
think about what we want to do about Z
because Z is really kind of not a real
dimension in our system because since
the way time app games work you don't
really have Z in the same way that you
have x and y so it's hard to say but
anyway after we compute these tile
differences and then we actually go
ahead and do the math here to add in the
tile difference amount plus the offset
amount now we've got a real DX dy and DZ
but of course this is actually all going
to be in meters but we need our meters
to pixels in order to actually turn that
into pixels on the screen and these are
all in pixels from here this is all
rendering units so there's our meters to
pixels that gets added in there to
convert that difference that we did and
of course we have to pass the tile map
as well which i think is just gamestate
time okay so there we go and so I
believe that is roughly all we need to
do to get that guy going and of course I
got to return the results of course and
so I think that should be roughly
correct and of course it isn't
classically you gotta love that I think
that's just because I forgot that we
have to flip things around for our our
kind of non we don't really have a
renderer yet like I said so our
coordinate systems are a little ad hoc
here so of course yes this is where we
have to do our flip always which you
know is kind of annoying at the moment
but that will all get handled in our
renderer for us so it's it's really it's
not as janky as it seems like it has to
be the fact that that the the up and
down doesn't quite work the way that we
would like it to but anyway so yes what
we would like to do here is we'd like to
have the player
ideally go in the opposite direction
also let me see here we should also make
sure that we don't have a bug in our in
our offset X offset Y stuff I don't
think we do but we could double check to
make sure that we don't so let's go
ahead and double check everything here
so we're gonna take all of the tile
sighted meters the d2 YY is always going
up that goes up in tiles as well as in
as in our meters units there so that's
correct but yes this this is this is
wrong because obviously the the guy
supposed to go up not the coordinates
are inverted in the renderer as from
what they are in the game that didn't
seem like the bug we were having though
I don't know yes see we still get a
weird we still get a little yeah I was
gonna say didn't that was that was one
bug that we have I'm like there's that
weird kind of we get that kind of nasty
[Music]
thing where the X is the X is related to
the Y I must have had a typo in that
code let me go back and look at it for a
second
Oh fantastic yes I have tons of typos
wow those are amazing there we go all
right so I think we are good to go now
our dude is moving around to the camera
is where it's supposed to be but we have
a few other things that we would need to
handle in order to get everything
working properly also I should note that
we still have not finished our bitmap
routine so if we move to the top you
will notice I don't know if you can see
that that our guide doesn't actually you
can't clip off the front off the top of
the screen we have it to do in there
about that so those are the things that
we have to finish so let's get him
walking throughout the entire map for
now for example when he comes off the
top of the screen here you'll notice the
camera will never change locations
because we have never actually
programmed the camera to change
locations so he is and we and we also
are drawing him whether he's on the same
z plane as the camera or not so when
technically we would go upstairs will
never actually see that so we have a
bunch of stuff that we need to fix so
let's go ahead and fix all those we've
got about 15
look just so we can have things cleaned
up and working relatively well so we
could start working on our math having
math having real math is going to be a
pretty nice thing let me tell you it's
been a bit of a struggle to kind of go
through without ever having really
vectors or anything like that but you
know you got to pick an order to do
things in right and so it's always
important to kind of you know not not go
too far too fast alright so first things
first we always want to move the camera
to wherever the player is in Z I would
say right so no matter what happens I
would say the the camera P I'm just
gonna say that the ABS tile Z is always
gonna be the same as the player state
ABS tile Z right just so what if the
player goes up then the camera goes up
if the player goes down it goes down and
and so I think yeah there you go so now
we can actually get up and so the only
thing that now we have problems that the
player moves off the screen the camera
doesn't ever follow them right and
that's no good so what we want to do
here is we want to then say all right
the other thing we need to do is to see
whether the player ever gets more tiles
to the left or to the right than he
should be relative to the player now
what we could do if we're always locked
to screens there's a lot of different
ways we could do this you know it
depends whether we want to drop down our
own manual camera points and and this
would allow us to do different things
like having screens of different scale
sometimes there's there's just a ton of
stuff we could do here I'm trying to
keep it again relatively simple because
one thing at a time but we basically
have a problem with our tiles X and
tiles why were what we want to do is
that the player moves one screen to the
right or one screen to the left we want
the camera to follow them there right
and so the simplest way we might do that
is just basically say if we rounded the
players position to whatever the closest
center screen Center point was we want
the camera to always be looking at that
right and that's one way we could do it
I'm not sure if that's the smartest way
to do it or not
yeah it's really hard to say so one way
I mean you know let's let's put in
something let's put in something even
simpler let's say we've got this diff
this diff function here right like so
oops
in fact I guess we don't even really
need the diff function now that I think
about it well I guess we can you know
kind of want it
we can't probably do want the
dysfunction I don't know it's difficult
to say but I guess what we'll do for now
is say all right when the when the we do
the subtraction here then basically what
I'm gonna do is say if the the Delta X
is greater than a certain amount then
I'm going to go ahead and move the
camera forwards and if it's less than a
certain amount right I'm gonna move the
camera backwards I'm just gonna see how
that works out so basically how far is
it well I'd say it's it's that seventeen
by two number again right if the if he
moves basically more than one screens
worth away then he'll we'll go ahead and
do the change so I don't know let's see
what that number actually ends up being
if I have seventeen tiles across as I
think what we said it was normally on
the thing and so that's eight point five
is the midpoint so eight tiles in the
eighth tile right we have seven tiles on
one side seven tiles on the other side
and then the middle tile right so
basically if you were to get let's say
nine tiles away if you were to get nine
tiles away from the camera on the
x-direction that would be too many and
we'd want to flip to the next screen so
what we could do is say all right let's
take 9.0 F is the number times the tile
side and meters right and that is
basically going to tell us side in
meters that's gonna say that the player
moved too far away from the camera right
I'm just gonna go ahead and do that like
so and let's just see what that gets us
again we got to go upstairs first cuz we
can't get out of this room so we go out
it out there and then we go here
and oh that that is not oh well that did
exactly what I told him to do we're
supposed to move the full 17 tiles but
for some reason I only had it move one
tile which is not really gonna help us
here just say the least
alright let's try that again my bad that
was the house that was not very bright
so yes if I go out here now we should
see me come back on the other side which
is exactly what happens and that's all
good again we still we have to go fix
our problems so that this doesn't happen
so that's the next thing to do and then
we also have to fix up and down so here
we go I can walk out here and then I can
kind of walk up here and this is the
place where we would like to go off the
screen so again
hey man since we got live code editing I
don't have to walk all the way back
there I can just go ahead and say let's
duplicate this and so since it's 9:00 in
the direction I guess that would mean it
was 4:00 here is the tile sided meters
and so the dy is going to basically do
this right and that should give us some
better motion up and down as well right
so when we walk off the end there oh
okay so it's actually sorry it's not for
its 5:00 I just I was happening there
but we were right it's because we didn't
encompass that extra tile when we walked
on to that tile we were in neither
camera space the camera constantly would
flip back and forth going oh I'm too far
away oh I'm too far away oh I'm too far
away so you actually have to do yeah all
the way to the end of that fifth tile or
at least in the middle of it in order to
not have that sort of problem all right
so I believe we can now walk all around
the world with our guy which is nice so
it's good it's kind of a happy little
fellow what he's determined you know
he's happy but he's determined you know
that's how he is so anyway he's gonna go
up there let's go up there see here go
through here yeah so everything's nice
and happy everything's good no
complaints alright so basically all we
really need to do now to
to get ourselves back to a place that's
pretty stable for him walking around to
where we can start to talk about wanting
his movement code to be better is is you
know I'm I'm walking out there and I'm
clipping against the screen here we just
need to make sure that we do the math
right for for clipping off that edge of
the screen I think we already do the
math right for clipping off the other
edge of the screen meaning that if I was
gonna go down I think that works
properly like so for example going off
the screen this way just works right so
that's all fine but it's that it's that
it's not coming in off the min that we
haven't done yet so let's go ahead and
do that and draw bitmap let's go ahead
and make sure that this function now
properly handles that you notice that to
do here that we left in there which is
source rotates to be changed based on
clipping and so that's the problem so
basically what happens is our rectangle
that we're bleeding does properly get
clipped so we don't overwrite memory or
do anything bad like that but what we're
not doing is advancing the source row
and the basically that starting pointer
for where we're copying the pixels we
need to advance that by however much we
clipped the left and top edges of this
bitmap so basically this part right here
when we do this we need to basically
save an offset value we need to save us
like a source offset X and we need to
save a source offset Y just tell us why
we should be fetching pixels further in
because we aren't drawing the ones that
are off the screen right and to make
that a little clearer for folks who
haven't done this sort of thing before
when we're normally drawing right what's
happening is if we're clipping off the
other side of the screen we don't have
to adjust the point where we copy from
right all we do is copy less so when we
copy a row if we started here all we
have to know is we'll stop copying
before you know before you would have
otherwise which would be all the way out
here but if we were to clip off the min
edges of the screen right in the case
like this where we're clipping off both
of the minimum edges then we can't start
copying from here we actually need to
start copying from here and so we
weren't doing that and so obviously we
were going to have the
graphical glitches because what was
gonna happen is we were gonna start
copying from here but we were gonna draw
it to here which basically gives a
phantom translation of our bitmap down
and to the right and it makes it look
like it stops early because this is
still the clipping for it so it's it
basically translated our guy this way
and clipped him so he would just you'd
see like his head like there when his
head should be up here off screen and
his body should be here right so all we
need to do is just advance that pointer
pre advance that pointer to the right
location and that will totally fix the
bug that we have so all we need to do
here is basically go alright we have
this which is our source row but we
could go ahead right now and update it
to say that whatever our set X is we'll
move that many pixels in and whatever
our offset Y is we'll multiply that by
the bitmap with right and that will
offset it by that number of rows so that
way we'll get you know the the row
offset and the column offset we're all
good there so all we need to do now is
actually store them and of course it's
whatever it was whatever this value was
that this negative value is how is we
want to offset by the off up the
opposite of that right so there we go
and now we should be copying this guy
well or we'll just go ahead and just
straight up crash because it's
amateur programming our here on handmade
hero apparently I don't know exactly
what it did there oh right because
because I forgot that this bitmap is
bottom up right so basically we have to
actually go down we have to actually
subtract for each of the the source
offsets yeah not not not the brightest
move by KC it's true but again a lot of
this stuff is just since this is test
code you can't expect me to remember all
that stuff when we actually are doing
the full render code a lot of this will
be more commented and more directly will
have boil it down more and then you can
get mad at me so I'm not gonna Alice
shame that that was not an Alice shame
moment my opinion I'm gonna give myself
a bye on that one all right so anyway I
think our dude is pretty much okay now
you can see how he flips properly now
off either edge of the screen so that's
all good we'll try it on up as well just
in
sure that yep that's all good up and
down seeming to be good there no issues
yeah yeah everything is fine okay so he
can go adventure around are very sparse
and not particular interesting world but
at least everything is working the way
that we think that it should and so
that's good
that's all very nice and good the other
thing that we probably should do at some
point here is check our framerate
because of course at the current moment
you know we have we're doing this
rendering code without any optimizations
it's not Cindy it's not optimized at all
it's it's crazy and so we should
probably verify that all this crazy
stuff that we did without any thought to
the performance of it whatsoever and
we're not again we're also not even
using GPU so we're at a severe
disadvantage performance wise here so we
should actually just go and check
because we still haven't had a chance to
do anything in terms of a heads-up
display for ourselves I just want to
take a quick second to look to see what
our frame rate actually is in practice
so let's take a look at that and it
looks like we're still okay we are
hitting that that that 30 frames per
second goal and so we are we are in good
shape all right even with all of that
pig enos so I think that's about
everything that I wanted to do today I
can't think if there's anything else
that I thought that I needed to do I
don't think so
so maybe let's go ahead and go to the
Q&A a little bit early and trying to
think if there's anything else oh well
you know what there is one thing we
could do that I wanted to mention I
mentioned this in the forums to people
because they were having trouble with it
and I just hadn't had time to do it
myself we could just throw it at the end
here and that is that since we're doing
our live code loading sometimes the
problem a problem happens with Microsoft
Visual Studio which is that when the
compiler writes out the executable it
sometimes writes a suitable first and
the PVV second well I think it always
actually does that and and so the PDB
actually finishes writing after the
executable finishes writing in this case
I should say DLL because it's the DLL
that we actually care about so we write
that DLL out and then the PDB gets
written out when our hot loader goes to
load the executable in it will load that
executable almost immediately because
remember
you know 30 frames a second here so
what's gonna load it very very soon and
the PDB sometimes hasn't finished
writing so what will happen is Visual
Studio will fail to load the PDB and
then we can't set our breakpoints and
stuff right because the PvP is still
open for writing so what I wanted to do
is to show a little trick that we could
do here to avoid that problem people
were having trouble with this on the
forums and I told them how to fix it but
I figured people on the stream should
know as well and that's basically just
to create a lock file so all we really
have to do is just in in the direct in
the directory where we're going to put
that DLL right all we really need to do
is we just need to put a lock file in
there and so we can say waiting for TVB
and we can put that out to like lock
temp or something and then when we are
done we'll delete that lock that temp
file right and that lock dot temp file
basically just says don't load right now
because whatever you're going to load is
going to be stale and so if we look at
what happens if I do that when I'm doing
this compile here it's probably hard to
see because you can't actually we
probably can't catch it in time well you
know what I could do I might be able to
I might be able to show it here I'm not
sure if I will or will or will not be
able to catch it but essentially if you
think about it this way where's my build
up at and made that I don't know if you
can see it show up there at uh loops
that's not right that I don't know if
you can see it show up there probably
not yeah never actually it never
actually boots forth does it see if I
can get it to go there it was block of
time and if you can see that pause the
stream anyway there's a lock top temp
file now that gets created there and
that lock temp file will not get deleted
hopefully until after the PDB is loaded
because the compiler will have returned
entirely at that time so once we know
that there is that lock file in place
that's just a dummy file that's there to
let us know when that thing started and
ended right what I can do is I can go
ahead and just test to see if the lock
file is there and assume that whatever
compilation has to be go
on no matter how complicated this thing
gets will always wait and we won't
delete the lock file until all the
things that we need to have happen
before the hot loading occurs have
occurred right and so when we do that
sort of low game code thing I don't even
remember where that is at this point
it's a little game code what we'll do is
we can actually say when we go to load
that game code I think this thing
actually sets let's see here
yeah this thing gets the DLL last right
time so what we could do is when we
actually go to load the game code we
could check to make sure that the lock
file is not there right and we have two
places technically we could do that we
could do that really in either position
and I don't know which one we would like
to do it's really hard to say I think we
probably just want to do it here so I
think what we want to do and why is this
still there I believe we are getting the
proper path I think we're doing both of
those two do's we need to go check to
make sure if we haven't have a lot of -
duze lying around they don't have to be
there so basically what we could do
right here is just go ahead and and do
the if right here to see whether or not
that lock file actually exists and so I
think the easiest way to do that is just
to do like maybe a get file attributes
or something like that let me see what
the easiest way is to do that in to see
whether that that file exists I think
actually which you file exists I don't
actually know path file exists I don't
think that's a good I don't think that's
actually the function that we want
Windows 2000 professional requires
sloppy yeah I don't I don't actually
know if we want that doesn't seem like a
good thing
get file attributes might be the easiest
get file attributes e^x let's see about
that guy I could also look I don't think
there's ever follows this function I
think there is but we could double check
exists path exists copy file now so
let's go ahead and use get file
attributes e^x and basically that should
return false if we can't actually get it
right so we'll just call well literally
just call this thing right like so and
if it actually if it actually was there
then we'll be good to go
this okay so what we need to do here is
we need to have that file name whatever
that file name actually has to be and so
it's going to be source dealing on a
temp dealing them and lock file name
right like that and so we'll go ahead
and pass that lock file name now
whenever we do a winter cue load code we
need to do lock bold path and all right
this is a game code lock full path bat
source game code DLL and so here I
should just be able to do temp that with
LOC there we go lock full path and
that's I think just called it block dot
temp and there we go so I think oops I
think that should be sufficient I'm not
sure I think it is and so let's take a
look so if I go in here
well evidently not oh I did it backwards
again get file attributes so it's
basically if not it's supposed to be if
we don't see the file it should load and
so I think that should be fine but let
me just test to make sure that we still
have our hot loading enabled so okay
let's go got this guy going I'll make a
new frame maybe Oh
the hideous colors maybe I won't make a
new frame so I'll just move this guy
down here I guess we could go ahead and
and do a loop for now let's go ahead and
make him go up here
okay and so I don't know what do we want
to do let's see if our live code editing
will live code edit him to go backwards
instead so I'll go in here to handmade
dot CPP and go to the facing Direction
stuff and basically I'll just say oh
yeah whenever he's going to the right
let's actually make him face left and
vice versa
yeah there we go so should be good yeah
yeah all right
I'm satisfied okay so I believe we now
do need to go back to our originally
scheduled program we're a little bit
over now three minutes over the QA now
that we have taken care of that I think
everything is is is kosher now with that
yes I believe it is so let us go ahead
and go to the QA now that we've finished
that if you would like to have me answer
a question please put Q colon in front
of it so that I will see it I and that
starts now anything that you've put
already that's Q :
I won't see it's anything that starts
now and has a Q : in front of it I will
I will take a look at and please try to
keep the questions two things that
happened on today's stream or previous
streams so please try to save off-topic
questions or things about what we're
going to do in the future for pre
streams I try to show up about 15
minutes early to most streams I can't
always make it but I try to and I answer
off-topic questions at that time so if
you're interested in asking off-topic
questions that's totally fine but come
before the stream to do those most the
time I try to be here before them so
yeah let's see
genetic species can you do that live
code with a function call that could
just be a poke hmm I'm sorry I'm not
sure what that means can you do that
live code with the function call could
you be more specific
perhaps let's see he numeration x' and i
correct to say you've not used them in
handmade hero yet I'm guessing this is
simply because it's too early to know
what will eventually require a new
enumerations and not some other reason
uh did we really never use an enum that
may be true we may never yes so we
haven't ever I do use enums I'm not
avoiding them for any particular reason
we just haven't had like sets of types
or anything probably when we do like
entities you know our entity types might
be an enumeration or something like that
you know but yeah I'm not avoiding them
we just I guess they just haven't come
up yet why not layer the individual body
parts into a single bitmap that way you
only have to draw one image instead of
three well that's a very good question
and hopefully this is a very good answer
for you I want him to be very bouncy so
I want him to kind of hop along and I
want the three parts to kind of do this
sort of a thing right so I asked
young-shin to make sure that they were
separate so that he could kind of be
like a little springy guy that Springs
around and in addition to like squashing
and stretching the bitmaps I also want
them to move relative to each other if
that makes sense to really kind of give
that sense of of you know motion are you
wearing a blue cape like the handmade
hero today
no it's not a cape it's just a shirt I
don't actually have a cape a handmade
hero cape
let's see I just wanted to point out
there is a magnifying tool in Windows
that came with air oh yes it's true
unfortunately it's really hard to use at
least I find it hard to use
I like this other tool called zoom in
which I just haven't gotten around to
finding I don't know where it is I may
have to copy it from like an old version
of Microsoft developer studio or
something but it was so much easier to
use than the than the one that
came with than the one that they ship
now let's see what they've got this zoom
in I don't know if this is someone
else's stupid zoom in I want the actual
I want the actual zoom in that used to
come with the dev tools so there used to
be one and Microsoft SDK tools yeah yeah
I'll have to go hunt for it I'll have to
go hunt hunt for it because that's the
one I actually want I expose that could
use color cop in fact maybe I should
just use color cop because color cops
pretty awesome
yeah yeah but looks like it doesn't do
real-time oh well yeah I don't know I
want to go get that zoom in tool because
I don't like the one that comes there
and that's why I haven't been using it
it's too hard to use in my opinion
Andy's SD don't you want tested bugging
um you can't really we'll just have to
see if we no longer hit the problem
because there's no way to tell whether
or not we just got lucky you just you so
you just have to you have to test it
like lots of times you can't write
because it was only sometimes that MSV
see didn't actually do the reload so I
just wanted to test just that much and
then we'll see as we go forward if we
have if we have the problem where it
can't set breakpoints
girl and a bloom oh no I swore I didn't
mean to swear oh that's the second time
oh my goodness I don't know even what I
said that's how bad of a swear that was
that's awful okay I'm trying to keep
this the language okay for four kids and
you know normally I swear a lot I will
tell you so it's it's been rather
difficult can you add a standard def
include two handmade platform about
eight sure I can do that in fact people
have been asking for a few things in
here one was to get standard def in
there so that platforms could get some
platforms want that for size T this guy
right here and so that but the any other
thing people were asking for is they
were asking if maybe the utility
functions could be moved in there
because they were having trouble
compiling well in fact you can kind of
see what they are basically we're still
using handmade H in win32 and so what I
could do is I could I could force it to
stop doing that and and just do handmade
platform that age and that would tell us
what our what our stuff is that we're
missing right and so we would need to
move in basically all of this stuff for
the most part so we would need to move
in to the platform layer all of this
code I think probably let's see here in
there I don't know what else and get
controller so get controller or would
have to be in there as well where is
gate controller so those are the things
that the platform layer was currently
calling and I don't know that I really
want all of those in the platform data H
at the end of the day oops move that
down a little bit and so yeah I don't
know if I want all of those things in
there that that may not be the best idea
but at least now we can pile clean so
people who are reporting to other
platforms can go ahead and do that so
hopefully that helps them out a little
bit just making sure that they see our
win32 layer just only includes handmade
platform that age
and that's a little more consistent and
make it a little easier for them why
does the guy have no feet well I mean if
you look that right there should tell
you why he has no feet how do you know
which compiler options like CLR and
standard headers you want to use um I'm
not sure what you mean by that exactly I
mean essentially my general rule for for
standard headers and compilers is that
you want to include everything in the
platform layer and you want to include
as little as possible in the main code
so you you would ideally I feel like you
wouldn't want any includes in the in the
stuff that that gets actually included
in the game but the bottom line is
that's not actually physically possible
most the time because you need to get a
little bit of information I mean you
could duplicate what was basically
happening in these headers so you could
do that
but for the most part what you're trying
to do is minimize the stuff that you're
including to only be definitions of
stuff that you actually need in terms of
types but you don't want to include
anything else for the most part that's
the way I usually like to do it because
I like to make sure that all of my code
is in my code and then I don't call out
into the library for anything so that I
know absolutely everything that's going
on and I can guarantee that everything's
portable and so on and so forth but yeah
that's just me
in terms of in general how you decide
what you want to do it's whatever you
want to use like I mean if you want to
use stuff
I mean basically the way to to know
about size T is just that if you go to
any kind of reference on C++ or C you
can kind of see like what it gets what
you need to include to use it so for
example in C++ if you're using the
standard size T it tells you here like
that's the include that that comes with
if you're looking at the the C library
I know where that would be exactly I
know who says where that is
here you go there to find the header
file standard def dot H so you kind of
have to go hunting for them or you can
search in your C compilers include
directory to try to find where they are
but it can be a little hairy when you're
like I want to use this language feature
where is it right so I don't know so I
don't know if that's exactly what you
were asking if you want to ask a more
specifically I can try to answer it
maybe perhaps a little bit better
changing the literal value of a variable
is a peek and poke technique poking a
value into a memory address oh I see
what you're asking okay yes for the live
code it is not poke based for what
you're saying it is full-on live code so
for example what we were doing there is
when like for example you're moving this
guy around we could actually you know
change the code to do anything we wanted
we could we could change it to do
absolutely anything so for example we
could just go into the actual code where
the guy was was being drawn right in the
draw bitmap code and we could just pull
on you know draw more heads right I mean
if we wanted to we could just we could
just do you know anything and there's a
second head on the guy maybe we could we
could go in and say we want to draw lots
of heads on the guy head count our head
index equals zero
head index is less than 10 plus plus
head index and then you know you get
into this kind of a situation where you
just have so many heads you don't really
know oops I mean header in that head
like so right and this is still all
running you know totally fine and you
can like I do the loop live code editing
thing that I was doing before where the
dude kind of does whatever he's thing is
that he does and that can be running all
the while if you want to right and so I
can switch up what I'm doing here I can
I can remove that and just draw one of
them right like that I could I could do
anything I wanted to so yeah we've got
we've got pretty much as as
Hardcore live code editing as you can
get in a reasonable amount of time I
have some harder core stuff where you
can actually change data structure
layouts that I've done in the past but
that's a huge thing that would take many
hours of explaining on the stream so I
decided not to do that one but we've
basically got as hardcore as you can go
without that so yeah it's pretty awesome
too we haven't had that a lot of chance
to use it yet because we're not tuning
stuff at this point really where this
becomes really great and we'll see this
possibly next week or maybe the week
after is when you're trying to tune like
the feel of an animation like in that
movement code or whatever being able to
do this where you can just see them
walking around and tune it and tune it
and tune it is it's pretty awesome so
I'm looking forward to that
what will happen if you have an item
that is in front in one view but in the
back on another since it seems you've
hard-coded the order in which they're
drawn will you reorder them based on the
view or some other rendering technique
so it depends largely I suspect that the
way your okay so this is just some code
that we put in here I feel like I say
this a lot but I guess it doesn't
necessarily often come through all of
this is test code none of the code that
we have written in anything in here will
actually get used right it's all
spec'ing out our game engine so we will
not be drawing the player anything like
this in the shipping version of the game
right it will literally bear absolutely
no resemblance to going on what's going
on here all of the stuff we are learning
in that I'm explaining while we go
through it will absolutely be important
because we are every single last thing
that we've learned here will be crucial
in our making the engine good but none
of this is how you'd actually do it so
when I say that I'm just drawing a
couple things in here so we can put the
hero in that's literally what I mean
what we will actually be doing is will
actually have a number of ways in which
things actually get sorted into the
scene and you'll see that once we
actually get to the point where we have
a renderer as opposed to just some test
code that sense why don't use the Emacs
calc the reason is actually cuz I have
not bound a key to it yet I only just
figured out that was there like
accidentally on the basic Emacs ik Emacs
has so much stuff in it that I only know
like 0.5% of the things that are in
there and so I need to remember to buy
the key to it eventually so that I can
just quickly hit it in calc so I get
meta X quick cash cow blah blah blah
takes too long but yeah I'm gonna buy
the key to at some point
oh so I'm going to sing that maybe I can
get zoom in at sysinternals calm is that
true
Salinas Utilities zoom it zoom it is
different than zoom in
interesting
huh
well to be honest with you though I'm
kind of curious about that and since I
obviously love mark russinovich I I
might be inclined to take a look at that
guy I did kind of want zoom in but zoom
it sounds like fun
I will say so maybe we'll check that out
yeah all right thank you for for
mentioning that yeah that could be
useful let's go ahead and close that
down there when you panned off the mint
edges can you explain how the head was
redrawing over the body so redrawing
over the body I'm not sure what you mean
by the head was redrawing over the body
well I mean I can sort of just quickly
go through what was happening there and
hopefully answer the question as part of
that so and just for the the fellow who
was asking about how extensive are our
live code editing was I will go ahead
and and introduce a bug in the code
while it's live there we go all right so
I'm going to turn off the loops live
code editing here and go ahead and and
get us to a point where we could
actually see that that happening so this
is what was happening right you can see
that bug now that I've commented out the
line so the head wasn't redrawing over
the body that was not actually what's
happening what's happening is once we
hit the minimum edge of the screen right
so remember the bitmap is bigger here
because it's just a bunch of alpha empty
alpha around that guy once we hit the
edge of the screen and we keep going
forward what we're essentially doing is
we've we are now clipping the blit
rectangle like the blitt rectangle is
like this big right and in fact you know
what I could do to just to show this to
you I could go ahead and right in here
the our channel always on for example
like I could do something like this
right
oh but I have to do it just for dudes
just for the little dude there mmm hmm
how do I want to do that
well the way I could do that is say if I
was clipped I suppose so I could do I
could I could do it this way if what did
I call that variable source offset so if
source offset X or a source offset Y
draw the red channel oops so what I've
done is I've made it so that you can see
the entire area of the blip once it
starts clipping when it clips off the
minimum edge right so hopefully you can
see what happens I move up there and now
my rectangle is flush against the side
as I move further over our rectangle
properly clips to the size that it
should be it correctly sets the size of
the blit but it is not changing the
offset in the bitmap where it's copying
the values from so it's always copying
as if it were going to copy the whole
thing but it just gets clipped out
entirely right as that as the rectangle
shrinks and shrinks it's only copying
less and less so what we need to do to
fix that problem is we need to copy from
further in at the bitmap as we fall off
this edge of the screen we need to move
in on the source the place for copying
from we need to move in so that he moves
over even though he's only copying a
little bit so it's copying this you know
this part from the rightmost edge of the
bitmap base so you could think about it
it's doing that right and so when that
happens right go ahead and turn the bug
off now what's going to happen is
essentially you could still see it's
only bleeding this this piece right it's
only blending that rectangle right there
but what it's doing is it's skipping
when it copies a row it's skipping the
first end pixels where n is however many
however far off the edge we were right
and so that allows him to move all the
way off right so does that make a little
more sense right we didn't have to do
that when we were clipping on the other
side of the screen because on the other
side of the screen we're going from the
left to the right when we copy a row so
all we had to do is stop early so the
this this for loop that's going to a max
X when we clip the max X that just that
just works that just solves the problem
right there
we set the max X right here right here
right when the max X is greater than the
buffer width so when the max X would be
off this edge we'd go ahead and stop it
and we set it to that that edge that's
all we need to do because we just
stopped copying the row right we just
stopped copying the row early that's it
right but when we're trying to move the
guy by clicking the keyboard when I'm
focused in the other window but on the
other edge it's not that simple because
if we were to just stop copying the row
early we get what we saw before where
the guy appears to stop again clamp
against that edge because it's still
copying the pixels from the beginning of
the bitmap where we don't want to copy
those pixels right so hopefully that
makes more sense I'll go ahead and
remove that there and there you go
so now we're back to normal oops can't
wait to do a better player movement code
it's awful trying to get through these
doors yeah I'm just like every time I
try to go through a drawer I'm like I
gotta fix that
do you ever write tests or does the
average game not have unit tests well so
you didn't test I've covered this a
couple times before I'll just say
quickly again unit tests aren't very
useful in games because that not many
things have the kind of well-defined
repeatability that you need to make unit
testing successful but sometimes you do
and so for like the renderer for example
where you that would probably be a place
where we do unit tests and we will have
some performance tests which look a lot
like unit tests they're not really
testing correctness as much as they're
testing speed so we'll have some of that
so you will see a little bit of that you
just don't see as much of it as you
could in other disciplines where the
state space is much simpler games have
huge state spaces that are that are very
different from the kinds of code that
that is usefully tested by unit tests
and so usually if you were doing unit
tests on a game you're often testing
things that don't really that aren't
really the hard part so you'd like your
bulletproofing your easy cases by
writing unit tests in most game code and
that doesn't really help you but there
are places where you can use it and we
will use it I suspect on the stream in a
couple of places we just haven't gotten
anything we're we're still doing
exploratory work on how we want the
engine designed and so until we get into
some code that we think that we're gonna
ship there's really not much that much
point in doing unit tests right because
you just kind of wasting your time
you're wasting your time bulletproofing
something that you're out playing ship
does this form of live coding work with
adding member variables to structs in
some cases yes in some cases no like I
said there's the harder data data layout
stuff is something we didn't do because
it was going to be a very much more
involved process to do that it involves
writing medic ode and stuff and so I
didn't want to do that but you can add
to like the end of structs in certain
situations but you can't rearrange data
members and the reason for that is
because well you I mean you could as
long as there weren't any of them in use
yet right but assuming that there are
ones in use they won't get remapped and
so what you need to do is you need to go
in and remap all of the ones that were
different now and we yes so we didn't
implement that how does this test code
help with the Future architecture since
it all gets dumped so basically what it
does is it will define exactly what we
want our engine to do I always say write
the usage code first and I really really
really mean that never write an engine
without knowing exactly how the game is
going to use that engine and that is
what we're doing right now so we're
basically just building a game doing
whatever it is that we want to do first
and then what we'll do is we'll just
kind of pull out those pieces and turn
them into real engine components as we
go and we already did a little bit of
that with our tile map we haven't done a
whole lot but we've already made the the
tile map stuff work kind of that way
where we've defined what it need to do
and we just haven't we haven't gone and
done like full hardcore engine stuff on
it yet but we did pull it out into a
little system and so that's the way
things will work so don't think of it as
dumping think of it as continually
evolving but the point that I'm trying
to make before was that none of the code
that we wrote as written will be what
ships in the game so you don't really
have to worry about it at that level you
just have to look at it and go okay what
does this do right now and why do we
want it to do that and what is what do
we need the engine to eventually do for
us in that case so the question that the
person asked about sorting is actually
totally fine to ask a little further
down the road when we're trying to
figure out how we want to do things
attached to guys so that they start
right and all those sorts of things but
you know that's not really
at this point we're not really trying to
solve those kind of problems right now
once we get to them we'll think about
how we want them solved we'll spec that
for the engine push it aside and off you
go
I'm not sure if this is true I'm
assuming you are making the guy clip
when leaving the screen but why make it
clip if you can just make it follow the
yellow box which might clip the guy
itself again I really sorry I'm not sure
I understand the question yeah I
apologize I'm not sure I understand the
question so I can't really add much to
that if streaming assets will be
required to display all visual
information will there be some type of
manual limit placed on a potential
generation to ensure that all assets
will never be required for a single room
well that's kind of getting ahead again
of where we are but the simple answer to
that is it depends on what our asset
plan is it depends whether our assets
have a degradation path or not though
end of questions right at the end of
questions how is that possible that is
just - that is a good omen people well
ladies and gentlemen thank you very much
for joining me for another episode of
hand made hero this was a pretty fun one
I'm kind of glad we have a little dude
moving around now that's a little bit
satisfying and it makes me want him to
have a nice sort of feel as he moves and
a nice animation as he moves around and
so I feel like that kind of answers my
question of what we should do next I
think I definitely do want to go ahead
and say let's animate the guy next and
make him have kind of a nice feel as you
move them around because that'll
basically let me start talking about the
math and let us get into some kind of
really interesting stuff yeah I think
that's that's that's what we want to do
so I think tomorrow what we'll do is
we'll end off well I'll take a look at
my sheet of stuff that we've postponed
tomorrow will basically be our final
clean-up day we'll just go through
everything anything that we want done
before then and then let's let's just go
ahead and say unless there's some major
turnaround over the weekend or something
let's just go ahead and say that Monday
is going to be our day to start some
serious math action because that's going
to power us up a lot and we're gonna
need that power for all the stuff that
we're
want to do so please consider joining us
for that for that episode Monday 8:00
p.m. PST we will be back here but if you
would like to catch us tomorrow tomorrow
is the stream for our friends in Europe
obviously on Fridays we always go ahead
and do a stream earlier in the morning
so that people on the time zones can
catch up set of 8:00 p.m. tomorrow's
will be 9:00 a.m. Pacific Standard Time
in the morning so if you are interested
in catching sort of the the final the
final step in our in our current series
of handmade here uh stuff before we
start the math please join us tomorrow
at 9:00 a.m. Pacific Standard Time I
know it's a little bit early I will be
groggy so will everyone else but we'll
get through it with a little bit of
coffee almond milk I suspect and I would
love to see you there again if you are
interested in following along at home
and you have not done so you can always
PR to the game and that comes with the
full source code so you can always
download every night after we finished
programming you can always download the
latest source code and follow along at
home it also comes with the test assets
that we're using here so you can you
know use those as well and see you can
you can kind of play around with them
mm-hmm just like we're doing similarly
if you want to support the video series
we have a patreon we also have a news or
patreon I don't actually know you
pronounce that
I suppose patreon I'm not sure but you
can subscribe to that if you want
support the video series and we have a
news and forum site you can go to which
has a lot of great information on it
it's got the schedule for the week
posted it's got an episode guide with
all the previous episodes and people
submit time-coded sort of jump lists and
you can jump around in them which is
kind of handy there's a coding reference
section which has ports to other
platforms if you're trying to follow
along the Linux or Mac there's some
great resources for you there and of
course there is a code discussion forum
if you want to ask questions so please
check it out if you're trying to learn
from the stream that's a great place to
go a lot of really helpful people up
there and people have done some really
great stuff so I highly recommend it
alright thank you everyone for joining
me and I hope to see you tomorrow and
Monday as well so take it easy everyone
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.