Skip to content

Commit 8f3330b

Browse files
committed
some minor adjustments
1 parent a55aec9 commit 8f3330b

9 files changed

+57
-115
lines changed

qor.make

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ OBJECTS := \
7474
$(OBJDIR)/Mesh.o \
7575
$(OBJDIR)/Material.o \
7676
$(OBJDIR)/Main.o \
77+
$(OBJDIR)/DynamicTyping.o \
7778
$(OBJDIR)/Engine.o \
7879
$(OBJDIR)/DummyPartitioner.o \
7980
$(OBJDIR)/TrackerNode.o \
@@ -200,6 +201,9 @@ $(OBJDIR)/Material.o: src/Material.cpp
200201
$(OBJDIR)/Main.o: src/Main.cpp
201202
@echo $(notdir $<)
202203
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -c "$<"
204+
$(OBJDIR)/DynamicTyping.o: src/DynamicTyping.cpp
205+
@echo $(notdir $<)
206+
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -c "$<"
203207
$(OBJDIR)/Engine.o: src/Engine.cpp
204208
@echo $(notdir $<)
205209
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -c "$<"

qor.vcxproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
<ClInclude Include="src\Shadow.h" />
151151
<ClInclude Include="src\Node.h" />
152152
<ClInclude Include="src\DummyPartitioner.h" />
153+
<ClInclude Include="src\DynamicTyping.h" />
153154
<ClInclude Include="src\IStateManager.h" />
154155
<ClInclude Include="src\IRealtime.h" />
155156
<ClInclude Include="src\GUI.h" />
@@ -165,7 +166,6 @@
165166
<ClInclude Include="src\Console.h" />
166167
<ClInclude Include="src\RenderBuffer.h" />
167168
<ClInclude Include="src\ISuperParent.h" />
168-
<ClInclude Include="src\Rules.h" />
169169
<ClInclude Include="src\IStaticInstance.h" />
170170
<ClInclude Include="src\Util.h" />
171171
<ClInclude Include="src\IFallible.h" />
@@ -206,6 +206,8 @@
206206
</ClCompile>
207207
<ClCompile Include="src\Main.cpp">
208208
</ClCompile>
209+
<ClCompile Include="src\DynamicTyping.cpp">
210+
</ClCompile>
209211
<ClCompile Include="src\Engine.cpp">
210212
</ClCompile>
211213
<ClCompile Include="src\DummyPartitioner.cpp">

src/DynamicTyping.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "DynamicTyping.h"
2+
3+
unsigned int DynamicContext :: inherit(std::string name, std::vector<unsigned int> types)
4+
{
5+
// TODO:
6+
return 0;
7+
}
8+
9+
bool DynamicContext :: isType(unsigned int type, unsigned int type_cmp)
10+
{
11+
return false;
12+
}
13+

src/Rules.h renamed to src/DynamicTyping.h

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
#ifndef _RULES_H
2-
#define _RULES_H
1+
#ifndef _DYNAMICTYPING_H
2+
#define _DYNAMICTYPING_H
3+
4+
// Provides dynamic classification (attributes, flags, inheritence) of objects for
5+
// scripting. Users can define types and flags and tag them to existing scriptable
6+
// objects for better user game logic.
37

48
#include <vector>
9+
#include <map>
10+
#include <algorithm>
511
#include <boost/dynamic_bitset.hpp>
6-
// Rules
7-
// Lays out the game mechanics, items, weapons, and provides scriptable interface to them
12+
#include "IScriptable.h"
813

9-
// eventually stuff like this (less stringly tho, using ID system preferably):
1014
// rules->addType("rocket")
1115
// rules->classSpec("rocket")->inherit("ammo")
1216
// inventory->addItem("rocket", 5);
1317
// if (inventory->anyOfType("ammo")) {
1418
// // etc...
1519
// }
1620

17-
class ClassSpec
21+
class DynamicType
1822
{
1923
public:
2024

21-
ClassSpec(const std::string& name):
25+
DynamicType(const std::string& name):
2226
m_sName(name)
2327
{}
24-
virtual ~ClassSpec() {}
28+
virtual ~DynamicType() {}
2529

2630
bool inherit(unsigned int id) {
27-
if(m_Types.find(id) != m_Types.end())
31+
if(std::find(m_Types.begin(), m_Types.end(), id) != m_Types.end())
2832
return false;
2933
m_Types.push_back(id);
30-
return true;
34+
return true;
3135
}
3236
unsigned int id() const { return m_ID; }
3337
const std::string& name() const { return m_sName; }
3438

3539
private:
3640

37-
unsigned int m_ID; // ID of type, also index in Rules' class member m_Types
41+
unsigned int m_ID; // ID of type, also index in DynamicContext' class member m_Types
3842

3943
std::string m_sName; // name for scripting and lookup
4044
std::vector<unsigned int> m_Types; // inherited type info
@@ -45,24 +49,24 @@ class ClassSpec
4549

4650
boost::dynamic_bitset<> m_Flags;
4751
std::map<unsigned int, std::string> m_FlagNames;
48-
}
52+
};
4953

50-
class Rules : public IScriptable
54+
class DynamicContext : public IScriptable
5155
{
5256
private:
5357

5458
public:
5559

56-
std::vector<ClassSpec> m_Types; // indexed by type id (array position)
60+
std::vector<DynamicType> m_Types; // indexed by type id (array position)
5761

58-
Rules(std::string fn):
62+
DynamicContext(std::string fn):
5963
IScriptable(fn)
6064
{
61-
m_Types.push_back(ClassSpec("object"));
65+
m_Types.push_back(DynamicType("object"));
6266
}
63-
virtual ~Rules() {}
67+
virtual ~DynamicContext() {}
6468

65-
unsigned int addType(ClassSpec spec) {
69+
unsigned int addType(DynamicType spec) {
6670
m_Types.push_back(spec);
6771
return m_Types.size()-1;
6872
}
@@ -71,24 +75,19 @@ class Rules : public IScriptable
7175
for(auto itr = m_Types.begin();
7276
itr != m_Types.end();
7377
++itr)
74-
if(spec.name() == name)
78+
if(itr->name() == name)
7579
return 0;
7680
else
7781
return itr->id();
7882
}
7983

8084
// makes a new type that inherits from other types
81-
unsigned int inherit(std::string name, std::vector<unsigned int> types) {
82-
// TODO:
83-
return 0;
84-
}
85+
unsigned int inherit(std::string name, std::vector<unsigned int> types);
8586

8687
// deep lookup if a type matches another type
8788
// warning: one-way relationship possible here
8889
// square is rectangle, rectangle is not always square, etc.
89-
bool isType(unsigned int type) const {
90-
91-
}
90+
bool isType(unsigned int type, unsigned int type_cmp);
9291
};
9392

9493
#endif

src/IScriptable.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _SCRIPTABLE_H
33

44
#include <string>
5+
#include "IConfig.h"
56

67
class IScriptable: public IConfig
78
{

src/Mesh.h

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class Mesh : public IRealtime
4444
std::vector<std::vector<glm::vec3>> UVs;
4545

4646
std::vector<std::shared_ptr<Mesh>> LOD;
47-
std::map<std::pair<std::weak_ptr<Node>, std::weak_ptr<Light>>, Shadow> shadows;
4847

4948
float minimum_lod;
5049
bool error;

src/RenderBuffer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RenderBuffer
1515
unsigned int height;
1616

1717
public:
18-
RenderBuffer(int _width, int _height){
18+
RenderBuffer(int _width, int _height) {
1919
m_FrameBufferID = 0;
2020
m_DepthBufferID = 0;
2121
m_Status = 0;
@@ -38,7 +38,7 @@ class RenderBuffer
3838
status();
3939
ASSERT(m_Status == GL_FRAMEBUFFER_COMPLETE);
4040
}
41-
virtual ~RenderBuffer(){
41+
virtual ~RenderBuffer() {
4242
if(m_FrameBufferID)
4343
glDeleteFramebuffers(1, &m_FrameBufferID);
4444
if(m_DepthBufferID)

src/Shadow.cpp

-45
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
#include "math/common.h"
21
#include "Shadow.h"
3-
#include "Log.h"
4-
#include "Node.h"
5-
#include "Mesh.h"
6-
#include "Light.h"
7-
using namespace std;
82

9-
//Shadow :: Shadow(Node* mesh_node, Mesh& mesh_ref, const Light& light_ref)
10-
Shadow :: Shadow(weak_ptr<Node>& mesh_node_ref, weak_ptr<Mesh>& mesh_ref, weak_ptr<Light>& light_ref)
11-
{
12-
m_bValid = false;
13-
14-
try
15-
{
16-
// set members
17-
m_wpNode = mesh_node_ref;
18-
m_wpMesh = mesh_ref;
19-
m_wpLight = light_ref;
20-
21-
// acquire shared_ptrs from weak_ptrs
22-
SharedData shared_data(m_wpNode, m_wpMesh, m_wpLight);
23-
if(!shared_data.valid())
24-
throw false;
25-
26-
// Get matricies so we can get all the vectors into world space
27-
glm::mat4 node_matrix = *shared_data.node->matrix_c(Space::WORLD);
28-
glm::mat4 light_matrix = *shared_data.light->matrix_c(Space::WORLD);
29-
30-
// now we go through the mesh and detect edges
31-
if(!generateEdges(shared_data))
32-
throw false;
33-
}
34-
catch(bool v)
35-
{
36-
m_bValid = v;
37-
}
38-
catch(...)
39-
{
40-
m_bValid = false;
41-
}
42-
}
43-
44-
bool Shadow :: generateEdges(Shadow::SharedData& shared_data)
45-
{
46-
return false;
47-
}
483

src/Shadow.h

+9-40
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,19 @@
11
#ifndef _SHADOW_H
22
#define _SHADOW_H
33

4-
#include <memory>
5-
#include "Node.h"
6-
#include "Mesh.h"
7-
#include "Light.h"
4+
#include <vector>
5+
#include "RenderBuffer.h"
86

9-
class Mesh;
10-
class Light;
11-
12-
class Shadow
7+
class ShadowBuffer
138
{
14-
public:
15-
16-
class SharedData
17-
{
9+
private:
10+
11+
std::vector<RenderBuffer> m_Buffers;
12+
1813
public:
19-
SharedData(
20-
std::weak_ptr<Node> n,
21-
std::weak_ptr<Mesh> m,
22-
std::weak_ptr<Light> l
23-
):
24-
node(n),
25-
mesh(m),
26-
light(l)
27-
{}
28-
std::shared_ptr<Node> node;
29-
std::shared_ptr<Mesh> mesh;
30-
std::shared_ptr<Light> light;
31-
bool valid() {return node && mesh && light;}
32-
};
33-
34-
Shadow(std::weak_ptr<Node>& mesh_node, std::weak_ptr<Mesh>& mesh_ref, std::weak_ptr<Light>& light_ref);
35-
//~Shadow();
3614

37-
bool generateEdges(SharedData& shared_data);
38-
bool good() { return m_bValid; }
39-
40-
private:
41-
std::vector<glm::vec3> m_vEdges;
42-
43-
std::weak_ptr<Node> m_wpNode;
44-
std::weak_ptr<Mesh> m_wpMesh;
45-
std::weak_ptr<Light> m_wpLight;
46-
47-
bool m_bValid;
15+
ShadowBuffer() {}
16+
virtual ~ShadowBuffer() {}
4817
};
4918

5019
#endif

0 commit comments

Comments
 (0)