-
Our game loop should be calling other functions
-
How do those functions access the data they need
-
link:examples/myFirstSprite/main.cpp[role=include]
-
What data does each need access to?
-
process_input ??
-
update ??
-
render ??
-
-
Should we limit the data that these functions can access?
-
discuss …
-
-
Should they be able to change that data?
-
process_input
-
game control state
-
-
update
-
world representation
-
-
render
-
world representation
-
-
The three main parts of our Game Loop should each only do some things
-
process_input
should only process input-
it should set controller state - what has happened in the world
-
abstract things, rather than low-level events
-
e.g. "jump", not "button X pressed"
-
-
it shouldn’t change the world state
-
it shouldn’t render anything
-
-
AKA stepSimulation (take a simulation step)
-
update
should only update the world state-
according to the world state and controller state
-
and how long to simulate for (duration)
-
it shouldn’t render anything
-
it shouldn’t handle input
-
-
render
should only render-
according to the world state
-
it shouldn’t change the world state
-
it shouldn’t handle input
-
-
The function/method signature tells you what you need to give the function, or order to use it
-
Good documentation should explain what the function/method does and how to use it
-
Many libraries provide only C interfaces, even if we’re using C++
-
e.g. SDL and OpenGL
-
int SDL_RenderCopy(SDL_Renderer* renderer,
SDL_Texture* texture,
const SDL_Rect* srcrect,
const SDL_Rect* dstrect);
-
What is each parameter?
-
What do they control?
-
-
What does the
const
do?
void SDL_GetWindowSize(SDL_Window* window,
int* w,
int* h);
-
How does this return data??
-
the function returns
void
!!!
-
-
So far our "World" consists of merely a single Sprite
-
things will get more complex and larger
-
-
What can we control about this Sprite at the moment?
-
??
-
Or what properties does it have??
-
-
Position - where on the screen
-
in what coordinate system
-
-
Size
-
in what coordinate system
-
-
Texture
-
We’re using C++, so we should have classes for our objects
-
to encapsulate data
-
to allow functions on that data
-
these don’t have to be the same classes …
-
perhaps contrasting with "normal" OOP
-
-
-
There are many ways to use classes for programming Games
-
especially with regards to efficiency and flexibility
-
-
The Entity-Component model is an alternative to inheritance
-
Composition vs. Inheritance
-
-
Each type of thing is an Entity - e.g. a Dragon
-
Entities have no logic
-
Each Entity has a set of components that belong to it, or each entity refers to
-
Position
-
Texture
-
Velocity
-
-
Each "system" processes through a certain set of entities
-
such as all those with a Position and Velocity, and updates the positions
-
such as all those with a Position and Sprite, and renders them
-
-
Could be overkill for within this module
-
So might an inheritance heirarchy with more than 2 levels
-
-
The separation of Data and Logic allows for significant performance enhancements
-
Especially related to caching
-
See Recommended Reading
-
You presently only have one source file -
main.cpp
-
Your present
CMakeLists.txt
file only try to make anexe
out of that single file
link:examples/myFirstSprite/CMakeLists.txt[role=include]
-
You should make new classes in new files (generally)
-
with a
.h
and a.cpp
, usually
-
-
You’ll need to tell cmake to compile those files into your program also
-
add them to list of files in
add_executable
-
-
What should you add?
-
Here’s an example
-
there are other ways of doing this
-
project(ConanTest)
cmake_minimum_required(VERSION 2.8.12)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(conanTest main.cpp myClass.h myClass.cpp)
target_link_libraries(conanTest ${CONAN_LIBS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "conanTest")
-
Listing all the source files for executable might become a list annoying
-
CMake supports globbing and recursive globbing
- glob
-
match files names according to a pattern. e.g.
*.txt
-
We could generate a list of files to add to our executable with a glob
-
WARNING: the CMake people recommend AGAINST this practice.
-
file(GLOB source_list "*.cpp" "*.h")
add_executable(conanTest ${source_list} )
target_link_libraries(conanTest ${CONAN_LIBS})
-
WARNING: Visual Studio will by default put new items in project’s root
-
in your
build
folder [frown o]
-
-
REMINDER: Everything in your
build
folder should be considered temporary-
you want to be able to remove the entire folder do get a clean system
-
-
IF you use "Add New Items" (or equivalent) in Visual Studio
-
REMEMBER to change the path where it creates the new file
-
to the root of your project (e.g.
gamesProgramming
) -
REMEMBER to add the files to your
CMakeLists.txt
file also-
Your project will still build without this
-
BUT only until your rerun CMake (e.g. when you moves machines)
-
-
-
You could choose to make a
src
folder at this point, to collect all your source code-
to make things more organised
-
you’ll need to update your
CMakeLists.txt
files to match the new locations
-