enable separation of game and engine components

master
BuildTools 4 years ago
parent a8d8616b77
commit c84dedd768
  1. 19
      demo/demo.cpp
  2. 19
      demo/demo.h
  3. 34
      main.cpp
  4. 22
      stuff/objects/argb.h
  5. 12
      stuff/objects/ray2D.h
  6. 2
      stuff/objects/square.h
  7. 3
      threedee.vcxproj
  8. 9
      threedee.vcxproj.filters

@ -0,0 +1,19 @@
#include "demo.h"
void game::run(SDL_Renderer* renderer)
{
ray2D ray = ray2D::trace(vector2(0, 201), vector2(1, 0));
ray2D ray2 = ray2D::trace(vector2(201, 0), vector2(0, 1));
SDL_RenderDrawLine(renderer, ray.start.x, ray.start.y, ray.end.x, ray.end.y);
SDL_RenderDrawLine(renderer, ray2.start.x, ray2.start.y, ray2.end.x, ray2.end.y);
std::cout << global::entList.at(0) << std::endl;
if (ray.hitEnt)
std::cout << std::hex << ray.hitEnt << std::endl;
//demo rays with moving object
global::entList.at(0)->x = global::mousePos.x;
global::entList.at(0)->y = global::mousePos.y;
global::entList.run(renderer);
global::entList3D.run(renderer);
}

@ -0,0 +1,19 @@
#pragma once
#include <Windows.h>
#include <stdio.h>
#include <iostream>
#include "SDL.h"
#include "../stuff/objects/vector2.h"
#include "../stuff/objects/vector3.h"
#include "../stuff/objects/ray2D.h"
#include "../stuff/globals/globals.h"
#include "../stuff/callbacks/callbacks.h"
#include "../stuff/objects/square.h"
#include "../stuff/objects/argb.h"
namespace game
{
void run(SDL_Renderer* renderer);
}

@ -3,13 +3,7 @@
#include <iostream>
#include "SDL.h"
#include "stuff/objects/vector2.h"
#include "stuff/objects/vector3.h"
#include "stuff/objects/ray2D.h"
#include "stuff/globals/globals.h"
#include "stuff/callbacks/callbacks.h"
#include "stuff/objects/square.h"
#include "demo/demo.h"
int main(int argc, char** argv)
{
@ -21,34 +15,20 @@ int main(int argc, char** argv)
window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN);
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateRenderer(window, -1, NULL);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SETRENDER_WHITE;
SDL_Event eventHandler;
global::entList.push_back(&square(200, 200, 50));
//global::entList3D.push_back(cube(200, 200, 100, 50));
while (global::running)
{
callbacks::handleCallbacks(&eventHandler);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderFillRect(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
ray2D ray = ray2D::trace(vector2(0, 201), vector2(1, 0));
ray2D ray2 = ray2D::trace(vector2(201, 0), vector2(0, 1));
SDL_RenderDrawLine(renderer, ray.start.x, ray.start.y, ray.end.x, ray.end.y);
SDL_RenderDrawLine(renderer, ray2.start.x, ray2.start.y, ray2.end.x, ray2.end.y);
std::cout << global::entList.at(0) << std::endl;
if (ray.hitEnt)
std::cout << std::hex << ray.hitEnt << std::endl;
//demo rays with moving object
global::entList.at(0)->x = global::mousePos.x;
global::entList.at(0)->y = global::mousePos.y;
global::entList.run(renderer);
global::entList3D.run(renderer);
SETRENDER_BLACK;
SDL_RenderClear(renderer);
SETRENDER_WHITE;
game::run(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(1);

@ -0,0 +1,22 @@
#pragma once
#include <Windows.h>
#include "SDL.h"
struct argb
{
BYTE a, r, g, b;
argb(BYTE a_, BYTE r_, BYTE g_, BYTE b_)
{
a = a_;
r = r_;
g = g_;
b = b_;
}
};
#define WHITE argb(255, 255, 255, 255)
#define RED argb(255, 255, 0, 0)
#define BLUE argb(255, 0, 0, 255)
#define GREEN argb(255, 0, 255, 0)
#define SETRENDER_WHITE SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255)
#define SETRENDER_BLACK SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0)

@ -1,14 +1,9 @@
#pragma once
#include <numeric>
#include "../globals/globals.h"
#include "vector2.h"
//temp
bool inRect(vector2 point, vector2 a, vector2 b)
{
return (point.x > a.x && point.y > a.y && point.x < b.x && point.y < b.y);
}
struct ray2D
{
vector2 start;
@ -45,4 +40,9 @@ struct ray2D
}
return ray;
}
//temp
static bool inRect(vector2 point, vector2 a, vector2 b)
{
return (point.x > a.x && point.y > a.y && point.x < b.x&& point.y < b.y);
}
};

@ -2,6 +2,7 @@
#include "SDL.h"
#include "vector2.h"
#include "argb.h"
/*
squares are the basic 2D entity
*/
@ -18,6 +19,7 @@ struct square : public vector2
}
void run(SDL_Renderer* renderer)
{
SETRENDER_WHITE;
SDL_Rect rect{ this->x, this->y, this->radius, this->radius };
SDL_RenderFillRect(renderer, &rect);
}

@ -154,6 +154,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="demo\demo.h" />
<ClInclude Include="sdl\include\begin_code.h" />
<ClInclude Include="sdl\include\close_code.h" />
<ClInclude Include="sdl\include\SDL.h" />
@ -241,6 +242,7 @@
<ClInclude Include="sdl\include\SDL_video.h" />
<ClInclude Include="sdl\include\SDL_vulkan.h" />
<ClInclude Include="stuff\callbacks\callbacks.h" />
<ClInclude Include="stuff\objects\argb.h" />
<ClInclude Include="stuff\objects\camera.h" />
<ClInclude Include="stuff\objects\entityList3D.h" />
<ClInclude Include="stuff\globals\globals.h" />
@ -252,6 +254,7 @@
<ClInclude Include="stuff\objects\vector3.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="demo\demo.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="stuff\callbacks\callbacks.cpp" />
<ClCompile Include="stuff\globals\globals.cpp" />

@ -303,6 +303,12 @@
<ClInclude Include="stuff\objects\ray2D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\argb.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="demo\demo.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@ -314,5 +320,8 @@
<ClCompile Include="stuff\globals\globals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="demo\demo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading…
Cancel
Save