MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / main

Function main

engine/src/game.cpp:1116–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114}
1115
1116int main(int argc, char* argv[])
1117{
1118 // Initialize SDL
1119 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
1120 {
1121 std::cerr << "Failed to initialize SDL: " << SDL_GetError()
1122 << std::endl;
1123 return 1;
1124 }
1125
1126 G_initializeGame();
1127 window.createGLWindow("2D Platformer");
1128 GL_initializeGLObjects();
1129
1130 gametime.lastGameTime = gametime.getCurrentTime();
1131
1132 for (int joystick_index = 0;
1133 joystick_index < SDL_NumJoysticks() && !g_controller;
1134 ++joystick_index)
1135 {
1136 if (SDL_IsGameController(joystick_index))
1137 g_controller = SDL_GameControllerOpen(joystick_index);
1138 }
1139
1140 SDL_Event event;
1141 bool quit = false;
1142
1143 while (!quit)
1144 {
1145 while (SDL_PollEvent(&event))
1146 {
1147 switch (event.type)
1148 {
1149 case SDL_QUIT:
1150 quit = true;
1151 break;
1152 case SDL_WINDOWEVENT:
1153 if (event.window.event == SDL_WINDOWEVENT_RESIZED ||
1154 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
1155 {
1156 int drawableW = event.window.data1;
1157 int drawableH = event.window.data2;
1158 SDL_GL_GetDrawableSize(window.window, &drawableW,
1159 &drawableH);
1160 R_resize(drawableW, drawableH);
1161 }
1162 break;
1163 case SDL_KEYDOWN:
1164 if (event.key.keysym.scancode < NUM_KEYS)
1165 input.keyboard.bKeys[event.key.keysym.scancode] = true;
1166 break;
1167 case SDL_KEYUP:
1168 if (event.key.keysym.scancode < NUM_KEYS)
1169 input.keyboard.bKeys[event.key.keysym.scancode] = false;
1170 break;
1171 case SDL_MOUSEMOTION:
1172 input.mouse.lX = event.motion.x;
1173 input.mouse.lY = event.motion.y;

Callers

nothing calls this directly

Calls 11

G_initializeGameFunction · 0.85
GL_initializeGLObjectsFunction · 0.85
R_resizeFunction · 0.85
PointClass · 0.85
pollControllerStateFunction · 0.85
P_runFunction · 0.85
P_cleanupFunction · 0.85
createGLWindowMethod · 0.80
getCurrentTimeMethod · 0.80
PlayGUISfxMethod · 0.80
destroyGLWindowMethod · 0.80

Tested by

no test coverage detected